开发者

Does git fetch operate on ALL branches or just the current branch?

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 bra开发者_开发技巧nch2
git merge branch1

Or can I just do this:

git fetch
git merge branch1


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜