Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been developing a new feature on a new branch, on the side I have committed quite a few changes on my master branch.

I would like to know if it's possible to merge the master branch in my new branch to keep it up to date so I wont have too many merge conflict when my new feature is finished?

share|improve this question
Have you tried git-merge ? Help here. – karatedog Dec 20 '10 at 15:21
up vote 43 down vote accepted

You can either git merge master or git rebase master, in this case i would prefer git rebase.

Because git rebase makes it as if the changes on the feature branch were made on top of the changes on the master branch, which makes the version graph simpler.

Taking the example from the git rebase manual:

      A---B---C feature                             A'--B'--C' feature
     /                   --rebase-->               /
D---E---F---G master                  D---E---F---G master

However, git rebase is only suitable when the branch hasn't been distributed, or there will be confusion and extra work downstream, because the old commits A, B, C have now become new commits A', B', C'.

If someone has pulled your branch, or you have pushed it somewhere, you should merge into it instead, to avoid confusion and extra work on the other end. See Recovering from upstream rebase.

      A---B---C feature                    A---B---C---M feature
     /                   --merge-->       /       ,---’
D---E---F---G master                 D---E---F---G master
share|improve this answer
You should explain why you prefer rebase and what the difference is. Rebase creates a linear history - this might not fit this question. – Andreas Rehm Dec 20 '10 at 18:47
Ok if I understand it well: I have to checkout the master branch if the newfeature is not finished yet and a rebase if it's finished? – mnml Dec 20 '10 at 22:28
No, with the feature branch checked out, do git rebase master, and it will "rebase" the changes in the feature branch so that they are "based" on the changes in the master branch. If the changes in the master branch conflict with the changes in the feature branch, git will ask you to resolve them and continue, skip them, or abort. If you feel unsure you can checkout a test branch to try it on with git checkout -b test-feature feature (assuming your feature branch is named "feature"). – Christoffer Hammarström Dec 21 '10 at 6:40
I have done my rebase but now when I pull from another computer I can't see my branch anymore: I have done git checkout newfeature / git rebase master – mnml Dec 21 '10 at 14:32
What do you mean "can't see my branch anymore"? Anyway, git rebase should only be used if the branch hasn't been distributed, which i assumed was the case since you said it was a new branch, sorry about that. See Recovering from upstream rebase in the docs i linked to. You'll have to use git merge instead. And you can use git reflog to find your previous feature branch head if you want to get it back. – Christoffer Hammarström Dec 21 '10 at 15:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .