远程存储库包含各种分支,如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 clone<repo_url>-b<branch>(仅克隆特定分支)的存储库,则应修改<repo_name>/.git/config文件。替换或修改引用[remote“origin”]部分的fetch目标的行,让命令git fetch--all发现所有分支:

[remote "origin"]
        url = <repo_git_url>
        fetch = +refs/heads/master:refs/remotes/origin/master

确保将提取参数点设置为/heads/master。

小心git fetch,因为这会获取所有数据,所以可能需要很长时间。

其他回答

帮助我的是

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

git branch -r

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

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

使用此简单命令:

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

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

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 clone<repo_url>-b<branch>(仅克隆特定分支)的存储库,则应修改<repo_name>/.git/config文件。替换或修改引用[remote“origin”]部分的fetch目标的行,让命令git fetch--all发现所有分支:

[remote "origin"]
        url = <repo_git_url>
        fetch = +refs/heads/master:refs/remotes/origin/master

确保将提取参数点设置为/heads/master。

小心git fetch,因为这会获取所有数据,所以可能需要很长时间。

步骤如下:;

gitfetchorigin或gitfetch-all,这将把所有远程分支提取到本地,然后这是您可以使用的第二个选项。git checkout--跟踪原点/<要切换的The_remote_branch>

然后处理这个分支,您可以通过键入

git branch

它显示您当前所在的分支。