如何从 git 中的不同远程分支拉取
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41644776/
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
How to pull from a different remote branch in git
提问by Jawakar Selvaraj
I am trying to pull from one of branch in remote named "front" to a branch named "back":
我试图从名为“front”的远程分支之一拉到名为“back”的分支:
git checkout front
git pull
But i am getting error message like,
但我收到错误消息,例如,
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>.
What should I do now? Thanks in advance..
我现在该怎么办?提前致谢..
回答by rozar
- set up a remote branch
- 设置远程分支
git remote add origin [email protected]:user/repo.git
git remote add origin [email protected]:user/repo.git
- pull it
- 拉它
git pull origin front
git pull origin front
- create your branch (if back already exists don't bother with the -b flag)
- 创建您的分支(如果返回已经存在,请不要使用 -b 标志)
git checkout -b back
git checkout -b back
- merge front into back
- 前后合并
git merge front
git merge front
回答by Mad Physicist
The other answers do a great job explaining how to merge branches once you pull or fetch them from the remote. They all assume that your branches have matching names in both repositories, but this is not required by Git.
其他答案很好地解释了从远程拉取或获取分支后如何合并分支。它们都假设您的分支在两个存储库中具有匹配的名称,但这不是 Git 要求的。
To have a local branch "back" pull from and push to a remote branch "front", you just need to set up the trackingproperly:
要让本地分支“返回”从远程分支“前端”拉取并推送到远程分支“前端”,您只需要正确设置跟踪:
git checkout -b back origin/front
will create a new local branch "back" that will pull from remote "front". You can also set up an existing local branch with
将创建一个新的本地分支“back”,该分支将从远程“front”拉取。您还可以设置现有的本地分支
git branch --set-upstream-to=origin/front back
The last argument is not necessary if you currently have "back" checked out. See https://stackoverflow.com/a/2286030/2988730for lots more information on setting up your branches.
如果您当前已检出“返回”,则不需要最后一个参数。有关设置分支机构的更多信息,请参阅https://stackoverflow.com/a/2286030/2988730。
回答by Adam Young
It sounds like you're trying to git merge
the two branches together.
听起来您正在尝试git merge
将两个分支放在一起。
Here is the documentation for your convenience: https://git-scm.com/docs/git-merge
为方便起见,这里是文档:https: //git-scm.com/docs/git-merge
Since you're trying to merge "front" into "back", you need to checkout back. That can be accomplished by using this command: git checkout back
由于您试图将“前”合并为“后”,因此您需要向后结帐。这可以通过使用以下命令来完成:git checkout back
Once you have "back" checked out, just use the merge command to bring the two branches together: git merge front
一旦“返回”签出,只需使用合并命令将两个分支放在一起: git merge front
The command git pull
brings down information from the remote repository to update your local repository. It's not going to pull from any branches, only the branch you have currently checked out. It sounds promising, but it really isn't.
该命令git pull
从远程存储库中提取信息以更新您的本地存储库。它不会从任何分支中拉取,只会从您当前签出的分支中拉取。听起来很有希望,但事实并非如此。
Take a look at this post to learn more about git pull
and git fetch
: What is the difference between 'git pull' and 'git fetch'?. It's a great read!
看看这篇文章以了解更多关于git pull
和git fetch
:“git pull”和“git fetch”之间的区别是什么?. 这是一个伟大的阅读!