Home > Software engineering >  How to sync feature branch with master branch
How to sync feature branch with master branch

Time:06-22

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?

CodePudding user response:

You shouldn't need to rebase at all.

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

CodePudding user response:

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/

CodePudding user response:

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.

  •  Tags:  
  • git
  • Related