当本地不存在时,从远程 git 分支拉取代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8837980/
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
Pulling code from remote git branch, when it does not exist locally
提问by James Raitsev
When branch B
does not exist locally, but is on the remote repo,
当B
本地不存在分支,但在远程仓库上时,
git branch
* A
git branch -a
* A
remotes/origin/B
How can i pull B
to my local repo? Should i git checkout B
first? Should i pull
, while on branch A
?
我怎样才能拉到B
我的本地仓库?我应该git checkout B
先吗?我应该pull
在分支时A
吗?
Please help me clarify
请帮我澄清
采纳答案by c00kiemon5ter
If the local branch b
does not exist, then git pull
and then simply git checkout b
and the branch will be created automatically.
Other options would include a git fetch origin/b
如果本地分支b
不存在,则git pull
然后简单地git checkout b
将自动创建该分支。其他选项包括git fetch origin/b
回答by tee
Fetch all remote branches without merging anything:
获取所有远程分支而不合并任何内容:
git fetch
Then create a local branch (B) from the remote (origin/B) & checkout that branch to switch to it:
然后从远程(源/ B)创建一个本地分支(B)并签出该分支以切换到它:
git checkout -b B origin/B
Then you're in branch B & you can pull in A:
然后你在分支 B & 你可以拉入 A:
git pull origin A
回答by manojlds
You have to do:
你必须要做:
git checkout -b B origin/B
to create the local branch from the remote.
从远程创建本地分支。
回答by vijay
Helpful git tips:
有用的 git 提示:
To get a remote branch to local repository, Use IDE pull/fetch options or below command:
要将远程分支获取到本地存储库,请使用 IDE pull/fetch 选项或以下命令:
git pull <remote_branch_name> <local_branch_name>
git pull <remote_branch_name> <local_branch_name>
This will create a local branch, Example master.
这将创建一个本地分支,Example master。
To checkout a local branch to the current directory.
将本地分支签出到当前目录。
git checkout master .
This will get you project into the current working directory.
这将使您的项目进入当前工作目录。