简体   繁体   中英

How to sync feature branch with master branch

while working on my feature branch, I found that someone made changes to the master branch. The feature branch which I'm currently working on needs to sync with the master branch. Tried to use git rebase, but it doesn't work (expected to see some file conflicts).

There are many modifications to the current feature files. Do I need to git add and commit (but don't git push) these modifications before git rebase?

You can follow the following steps:

  • Run git checkout master
  • Run git pull --rebase origin master [To Update branch with remote repo]
  • Run git checkout feature
  • Run git rebase master
  • if you face conflicts then you need to solve those conflicts and run
    • git add <file_name>/ git add .
    • git rebase --continue
  • continue second step until you solve conflicts(remeber rebase compare changes commit wise)
    • Then run git rebase --skip if needed
  • After you successfullly aplied rebase you need to force push the changes
    • Run git push --force-with-lease origin feature (safer way of force push) OR git push -f origin feature

FOR REFERENCE: https://gitexplorer.com/

You shouldn't need to rebase at all. In fact, it's my opinion that rebasing is something you should do if you fully understand the possible consequences (rebasing can rewrite logs which is not usually a good idea for auditing changes, merging does not).

You can simply git fetch ; git pull origin master git fetch ; git pull origin master to bring in their changes, then fix any merge conflicts caused by that.

You need to rebase master:

git checkout master
git pull master
git checkout feature-branch
git rebase master

Your feature-branch commits will be ahead of last commit in master branch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM