远程存储库包含各种分支,如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

当前回答

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

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

其他回答

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

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

标题和问题混淆了:

Git获取远程分支我的同事怎么能具体地拉动那个分支。

如果问题是,我如何才能使用远程分支,或者我如何Git签出远程分支?,更简单的解决方案是:

使用Git(>=1.6.6),您可以使用:

git checkout <branch_name>

如果找不到本地<branch_name>,但恰好在一个远程中存在具有匹配名称的跟踪分支,请将其视为等同于:

git checkout -b <branch_name> --track <remote>/<branch_name>

参见Git签出文档

对于您的朋友:

$ git checkout discover
Branch discover set up to track remote branch discover
Switched to a new branch 'discover'

使用此简单命令:

git checkout -b 'your_branch' origin/'remote branch'

在我看来,这一行命令是获取和签出本地不存在的远程分支的最简单方法:git获取和git签出remote_branch

帮助我的是

1) 查看所有可用的远程分支(例如“远程分支名称”)

git branch -r

2) 使用远程分支名称创建本地分支

git fetch && git checkout 'remote-branch-name'