tags:

views:

26

answers:

1

I have a remote repo on github, and on my local machine I have a few different branches (so I can switch between the branches using "git checkout master", "git checkout branch2", etc.).
When I run the "git fetch" command, I am never sure if it's fetching updates for ALL of those branches or ONLY the branch I'm currently working in (the one I most recently "checkout"'ed).
In other words, if I'm working in branch2 and want merge in changes someone else made to branch1, do I need to do:

git checkout branch1
git fetch
git checkout branch2
git merge branch1

Or can I just do this:

git fetch
git merge branch1
+1  A: 

By default, it will fetch all HEADS from the remote repo.
But those branches are referenced by the refspec remoteRepoName/branchName

So in your case, that would be:

git fetch
git merge remoteRepoName/branch1

git remote can list the remote you have registered within your repo to get the right remote repo name.


Note: since you are using a DVCS, which introduces publication (push/pull, which is orthogonal to branching), you might want to fetch the same branch2 from the remote, and merge it in your local branch2. In other words, "someone else" doesn't have to make a "branch1" to contribute to your development effort. He/she can make a branch2, which will exist in the "namespace" of the remote repo, and will be fetch/merge (i.e. "pull") in your local repo.

VonC
Would this be equivalent to "git fetch; git checkout branch1; get merge origin/branch1; git checkout branch2; git merge branch1;"? (Sorry, still kinda new at this -- now sure what HEADS or refspec means)
Jordan Lev
@Jordan: actually, if you merge `remote/branch1` into `branch1`, you can just: git checkout `branch1` (if you weren't already in this branch) and `git pull` (which will fetch, then merge). But if you want to merge `remote/branch1` to local `branch2`, then you don't have to merge it first in your local `branch1`.
VonC
@Jordan: see http://longair.net/blog/2009/04/16/git-fetch-and-merge/ for more on this fetch and merge process.
VonC