当本地不存在时,从远程 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:20:26  来源:igfitidea点击:

Pulling code from remote git branch, when it does not exist locally

git

提问by James Raitsev

When branch Bdoes not exist locally, but is on the remote repo,

B本地不存在分支,但在远程仓库上时,

git branch
 * A

git branch -a
 * A
  remotes/origin/B

How can i pull Bto my local repo? Should i git checkout Bfirst? Should i pull, while on branch A?

我怎样才能拉到B我的本地仓库?我应该git checkout B先吗?我应该pull在分支时A吗?

Please help me clarify

请帮我澄清

采纳答案by c00kiemon5ter

If the local branch bdoes not exist, then git pulland then simply git checkout band 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.

这将使您的项目进入当前工作目录。