Well for a start nobody should be working from master/main. That is for storing the code that is currently in Production!!
You should have a Production/Staging release branch that is used by your deployment engine to deploy to Production. Once successfully deployed, merge Production/Staging release branch to master/main
Allows you to be able to do HOTFIXes if/when required!
You should have a Testing/UAT release branch that is used by your deployment engine to deploy to Testing/UAT
Secondly you should refresh your feature branch from any changes made by others to the Testing/UAT release branch
You should create feature branches from that Testing/UAT release branch: eg feature/TestRelease
So to do this right, from CLI ie Window command or Bash
git checkout feature/TestRelease
(First time: git checkout -b feature/TestRelease origin/feature/TestRelease)
git pull
from UI ie GitHub, BitBucket, Azure DevOps Create your new feature eg feature/JIRA-875-LearnGIT based upon feature/TestRelease
back to CLI, make use you are on feature/TestRelease
git fetch
this will display: feature/JIRA-875-LearnGIT -> origin/feature/JIRA-875-LearnGIT
Copy it type and paste to get: (remove the ->)
git checkout -b feature/JIRA-875-LearnGIT origin/feature/JIRA-875-LearnGIT
it will change branch locally to feature/JIRA-875-LearnGIT
Do your stuff ie changes
then
git stash -m"Some description" git checkout -
(This will get you back to previous local branch ie feature/TestRelease)
from feature/TestRelease
git pull git checkout -
(This will get you back to previous local branch ie feature/JIRA-875-LearnGIT)
git rebase -
(Rebase repoints your feature branch to the end of the release branch: ie feature/TestRelease)
fix any conflicts
then
git rebase --continue
(Finishes rebase)
Then unstash your changes
git stash pop git add . && git commit --amend
then push
git push origin HEAD -f
Rebase repoints your feature branch to the end of the release branch
The golden rule of git rebase is to never use it on public branches; that is never on Release branches and master/main
Rebase your feature branch to your Release branch before Pushing your local changes to the git repro branch ie feature branch on Git server
Merge your feature branch to your Release branch, best done from UI ie GitHub, BitBucket, Azure DevOps
masteror just edit the commits you just made ontest-branch?