1

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?

2
  • 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? Generally, yes. Rebase has an "autostash" option (that will do a variant of this for you) but because it uses git stash, I don't recommend it myself. It's a good idea in general to make a lot of small commits anyway; you can use git rebase -i to organize them into more sensible, better commits later, as long as you haven't shared them with others yet. Commented Jun 22, 2022 at 9:46
  • 1
    Note that after committing, Seyed Amir KhalifehSoltani's answer will work, but there's an easier way: commit as usual, then run git fetch, then run git rebase origin/master. You do not need a local master branch at all! Commented Jun 22, 2022 at 9:47

3 Answers 3

3

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/

Sign up to request clarification or add additional context in comments.

Comments

2

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 to bring in their changes, then fix any merge conflicts caused by that.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.