git pull 在不同的分支上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34344034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git pull on a different branch
提问by nobled
If I'm working on a branch and then realize I need to merge another branch into mine here is my current workflow (for this example lets say that I'm working on my-branch and want to merge in master):
如果我在一个分支上工作然后意识到我需要将另一个分支合并到我的分支中,这是我当前的工作流程(对于这个例子,假设我在我的分支上工作并想合并到 master 中):
git stash
git checkout master
git pull
git checkout my-branch
git merge master
git stash pop
Is there a way in git to pull a branch other than the currently checked out one, or is there a better way to do this?
在 git 中有没有办法拉出当前检出的分支以外的分支,或者有更好的方法来做到这一点?
For example, here's what I'd like to be able to do (again lets say I'm on my-branch and want to merge in master
):
例如,这是我想要做的事情(再次假设我在我的分支上并想合并master
):
git pull master
git merge master
The git-pull man page says that a git pull is just a get fetch followed by a git merge, so is there a way to do the merge part of the git pull on a branch other than the one that's currently checked out?
git-pull 手册页说 git pull 只是一个 get fetch 然后是一个 git merge,那么有没有办法在当前检出的分支之外的分支上执行 git pull 的合并部分?
Or is what I'm asking for just not possible?
或者我所要求的只是不可能的?
采纳答案by Robert Kraaijeveld
Try this:
尝试这个:
git pull yourRepositoryName master
回答by Chris
I found an incantation that worked for me:
我找到了一个对我有用的咒语:
git fetch origin master:master
then (if you want to merge right away):
然后(如果您想立即合并):
git merge master
I was really surprised how hard it was to find an answer to this since it seems like it would be a common use case.
我真的很惊讶找到这个问题的答案是多么困难,因为这似乎是一个常见的用例。
回答by Peter
You could also try this:
你也可以试试这个:
git fetch
git merge origin/master
This won't update your local master
pointer, but it will merge the latest origin/master
into your current local branch.
这不会更新您的本地master
指针,但会将最新的指针合并 origin/master
到您当前的本地分支中。