I've been following this guide for working with distributed git projects: http://nvie.com/posts/a-successful-git-branching-model/. It has worked well but now I have run into a snag. I have created a local feature branch. I would like to keep this feature branch up-to-date with the latest changes made in dev
. Is this possible? I was researching this and found I would probably need to use rebase
. But there were so many options I didn't know exactly which one I needed to use. How would I do this?
Asked
Active
Viewed 2.0k times
16

Jeff
- 1,152
- 5
- 14
- 27
2 Answers
27
Periodically:
λ git checkout dev
λ git pull origin dev
λ git checkout myfeaturebranch
λ git merge dev

Matt Ball
- 354,903
- 100
- 647
- 710
-
So, when it's time to merge my feature branch back into `dev`, I shouldn't have to worry about any merge conflicts? – Jeff Aug 29 '13 at 18:58
-
Correct, though the tradeoff is having to resolve merge conflicts in the `git merge dev` step above. – Matt Ball Aug 29 '13 at 19:48
-
Is there any benefit to doing it this way as opposed to rebasing suggested by Derek S? – Jeff Aug 29 '13 at 20:08
-
4Conflicts are an absolute nightmare when rebasing. Rebasing gives you a nice history when there are no conflicts, but as soon as there are, I start running. – Matt Ball Aug 29 '13 at 20:12
-
If I understand, you are regularly merging `dev` into your feature branch. Isn't it always better to do the opposite? Merge your feature branch into a local dev, then rename the result as your new local feature. – Rivera Sep 20 '16 at 15:20
-
Awesome! Thanks! :) – Iram Bukhari Dec 01 '17 at 19:22
-
And what about all staged files you haven't update but you need to commit (in an ugly way) then in order to get up to date ? See this question : https://stackoverflow.com/q/9189867/2112198 – Burrich Dec 01 '17 at 21:23
9
Running git rebase dev
while on the feature branch should do the trick (update local dev from origin first, if necessary).
That will replay your changes from the feature branch onto dev, then sets the feature head to be the head of the new history.
Note: Only rebase
if your feature branch commits have not yet been pushed. It will rewrite your history. There are some caveats with rebase
which may or may not be worth the risk.

Derek
- 3,438
- 1
- 17
- 35
-
7I think this is the better way to do it, but you should ONLY do it if your feature branch commits have NOT been pushed. That's what the git documentation states. – DaBlick Nov 21 '16 at 15:46
-