문제

I need to be able to pull to a branch that I might not be on (in fact, assume for the sake of argument I don't know what branch I'm on). For example, I have a remote origin with a branch master that is tracked locally in the usual way by a local master using a tracking branch. Are there options or arguments I can supply to git-pull that will have the same effect as switching to master, pulling, and then switching back to whatever branch I started on?

Many answers here suggest that this is not possible, but the documentation's discussion of <dst> under <refspec> suggests that something like

git pull origin master:master 

will do the trick. Is that so?

도움이 되었습니까?

해결책

A git pull basically does a git fetch followed by a git merge.

Doing git pull for another branch is not possible, because doing git merge for another branch is not possible. To be able to do git merge, you need to checkout the target branch first. For this same reason, you cannot do git pull for another branch.

@torek added an excellent point:

And, to specifically address git pull origin x:y: git pull passes the x:y argument to git fetch, so git fetch does what it does; but then git pull attempts to merge into the current branch, regardless of x and/or y.

See this also for reference:

Merging Branches Without Checkout

다른 팁

I've never seen the master:master syntax. Generally: git pull origin e.g. master.

I think what you want to do is do a fetch first. Then you have the ability to merge any of the tracking branches, or switch to them.

A pull is basically a fetch followed by a checkout of the updates on the current (tracking) branch. All you want is the fetch.

git fetch origin master:master

Do you really need the merge feature of git pull?

If not, you could simply do:

git fetch
git branch -f master origin/master

This simply makes the local master to point on the same commit, the remote master points to.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top