I create a test branch from main branch and start working on it,but then my team push the changes to mainline of the package.So How can I update the main branch with the new changes that is push by my teammate, then How can I also update my test branch with those changes.
CodePudding user response:
In your setup main is a non-current branch. (Unlike other answers) There is a simple way to update a non-current branch without switching to it:
git fetch origin main:main
After that merge main into the current test using git merge main. Or rebase test on top of the updated main:
git rebase main test
If you prefer merge you can do everything in one command:
git pull origin main:main
This command does git fetch origin main:main and then git merge main at once.
With rebase there are two commands:
git fetch origin main:main
git rebase main test
CodePudding user response:
You need to back-merge main branch again after updating it on your local:
git checkout main
git pull origin main
git checkout test
git merge main
git push
CodePudding user response:
- Make sure you have committed all the changes in your current branch
git add -A
git commit -m "Some clear commit message"
- Go to your main branch, fetch the remote changes and merge to your local
mainbranch
git checkout main
git pull origin main
- Now go back to your local
testbranch and merge those changes with themainbranch
git checkout test
git merge main
- That's it. If there are no conflicts, branches will be merged automatically. Otherwise, read carefully the prompted message and follow the instructions.
