Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to keep local feature branch updated with changes made in dev?

Tags:

git

branch

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?

like image 563
Jeff Avatar asked Aug 29 '13 18:08

Jeff


People also ask

How do you keep feature branch updated?

Merge the changes from origin/master into your local master branch. This brings your master branch in sync with the remote repository, without losing your local changes. If your local branch didn't have any unique commits, Git will instead perform a "fast-forward".

How do I keep my local branch to date with master?

Might be good to recommend an initial "git checkout master; git pull" to ensure that the local master branch is up-to-date.


2 Answers

Periodically:

λ git checkout dev
λ git pull origin dev
λ git checkout myfeaturebranch
λ git merge dev
like image 69
Matt Ball Avatar answered Nov 15 '22 13:11

Matt Ball


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.

like image 37
Derek Avatar answered Nov 15 '22 14:11

Derek