远程存储库包含各种分支,如origin/davis_branch:

$ git branch -r
origin/HEAD -> origin/master
origin/daves_branch
origin/master

如何将daves_branch获取到本地存储库,以便它跟踪origin/davis_branch?

我尝试了:

$ git fetch origin discover
$ git checkout discover

当前回答

我键入了

git checkout <branch_name>

并且得到

Branch <branch_name> set up to track remote branch <branch_name> from origin.
Switched to a new branch '<branch_name>'

其他回答

如果你已经知道你的远程分支了。。。

git remote
=> One
=> Two

并且您知道要签出的分支名称,例如br1.2.3.4,然后执行

git fetch One
=> returns all meta data of remote, that is, the branch name in question.

剩下的就是结账

git checkout br.1.2.3.4

然后用它做新的树枝。

我键入了

git checkout <branch_name>

并且得到

Branch <branch_name> set up to track remote branch <branch_name> from origin.
Switched to a new branch '<branch_name>'

您也可以一次获取并签出远程分支:

git fetch && git checkout the-branch-name
git fetch

git branch -r

git checkout <branch_name>

使用gitbranch-a(本地和远程分支)或gitbranch-r(仅远程分支)查看所有远程及其分支。然后,您可以对远程执行git checkout-t remotes/repo/branch并创建本地分支。

还有一个git-ls-remote命令,用于查看该远程的所有ref和标记。