views:

54

answers:

1

Here's a common workflow hurdle I encounter often:

master is our "stable" branch

$ git status
# On branch master
nothing to commit (working directory clean)

create a module on a branch

$ git checkout -b foo
$ echo "hello" > world
$ git add .
$ git commit -m "init commit for foo module"
$ git checkout master
$ git merge foo

do work on master or other branches

Over the next couple weeks, more code will be committed to master directly and by other branches. foo branch will go untouched for this time period

resume work/make updates on foo branch

$ git checkout foo

Oh no! foo is massively out of date! I understand why, but I do need foo back in sync.

the question

How do I get the latest contents from the master branch?

+2  A: 

If you don't need the branch around:

If you've merged foo back to master, we not "git branch -d foo" to kill the topic branch, and then "checkout -b foo" in the future when you need to hack on it again?

If you do need the branch around:

You can rebase your topic branch against the master branch:

git checkout foo
git rebase master

Or:

git rebase master foo
Adam Vandenberg
Adam, consider the scenario where I need to temporarily "pause" development on the `foo` branch while I make quick changes on a `bugfix` branch. `bugfix` will be merged into `master`, but then it should be sync'd with `foo` afterward, too. Does that make sense?
macek
Adam Vandenberg
Adam, [`rebase`](http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html) is *exactly* what I was looking for; far more appropriate than deleting/recreating the topic branch, too. If you update your answer to "git rebase master", I'll be happy to accept it. (please do not specify `origin/master`, as I'm not dealing with a remote)
macek
macek