git 将远程分支拉入不同名称的本地仓库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12043236/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:25:22  来源:igfitidea点击:

Pull remote branch into local repo with different name?

gitgithubrepository

提问by Cosmin Atanasiu

Alright I did a little bit of research on this but I couldn't find an exact answer, so I have to ask.

好吧,我对此做了一些研究,但我找不到确切的答案,所以我不得不问。

I have 2 remotes: origin and repo2.

我有 2 个遥控器:origin 和 repo2。

I'd like to do something like

我想做类似的事情

git pull repo2 master

But this would pull the master branch of the repo2 into my master. Can I specify a different branch to pull into, for my local branch ?

但这会将 repo2 的 master 分支拉入我的 master 分支。我可以为我的本地分支指定一个不同的分支吗?

回答by KingCrunch

git checkout -b myBranchName repo2/master

回答by Ben Hymanson

The git pullcommand is a convenience function that does git fetchand git merge. If you only want retrieve branches from a new remote without trying to merge it into any working copy branch you can just use git fetch. You can then refer to git branch -avto see all the local and remote branches and operate on either remote as you like.

git pull命令是一个方便的函数,它执行git fetchgit merge。如果您只想从新远程检索分支而不尝试将其合并到任何工作副本分支中,您可以使用git fetch. 然后,您可以参考git branch -av查看所有本地和远程分支,并根据需要在任一远程分支上进行操作。