如何获取我的分叉 git repo 的所有分支

Sit*_*thu 2 git bitbucket git-clone git-branch

我已经在 BitBucket 克隆、拉取并获取了我的远程 git 存储库。但是我只能得到master分支。我在 BitBucket 的 repo 有 4 个分支:

  • 掌握
  • 修复/清理
  • 等/schema_note
  • 特征/样本数据

在此处输入图片说明

我已经找到了这个那个的两个问题。我遵循了这些问题中的一些说明。
当我尝试时git branch -a,我看不到其他三个分支。

*master  
 remotes/origin/HEAD -> origin/master  
 remotes/origin/master
Run Code Online (Sandbox Code Playgroud)

我试过了git checkout origin/fix/cleanup。我收到一条错误消息。

错误:pathspec 'origin/fix/cleanup` 与 git 已知的任何文件都不匹配。

我试过了checkout -b,但又出现了一个错误。

$ git checkout -b fix/cleanup origin/fix/cleanup
fatal: Cannot update paths and switch to branch 'fix/cleanup' at the same time.
Did you intend to checkout 'origin/fix/cleanup' which can not be resolved as com
mit?
Run Code Online (Sandbox Code Playgroud)

我也尝试执行oneliner。

for remote in `git branch -r`; do git branch --track $remote; done
Run Code Online (Sandbox Code Playgroud)

但它给了我本地的新分支origin/HEADorigin/master,而不是其他 3 个分支。我的回购发生了什么?

我试过git fetch --allgit pull --all。他们没有给我任何改变。

Sit*_*thu 5

我最终找到了解决办法。我调整了 git 配置文件。我变了

fetch = +refs/heads/master:refs/remotes/origin/master

fetch = +refs/heads/*:refs/remotes/origin/*

然后,$ git fetch --all为变化而努力。

Fetching origin
Password for 'https://myusername@bitbucket.org':
remote: Counting objects: 993, done.
remote: Compressing objects: 100% (581/581), done.
Receiving objects: 100% (966/966), 723.76 KiB | 8.00 KiB/s, done.
emote: Total 966 (delta 324), reused 964 (delta 322)Resolving deltas:   0% (0/32

Resolving deltas: 100% (324/324), completed with 21 local objects.
From https://bitbucket.org/myusername/myproj
 * [new branch]      etc/schema_note -> origin/etc/schema_note
 * [new branch]      feature/sampledata -> origin/feature/sampledata
 * [new branch]      fix/cleanup -> origin/fix/cleanup
Run Code Online (Sandbox Code Playgroud)

现在,$ git branch -a开始列出所有远程分支;

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/etc/schema_note
  remotes/origin/feature/sampledata
  remotes/origin/fix/cleanup
  remotes/origin/master
Run Code Online (Sandbox Code Playgroud)

最后,我checkout为每一个分支。

TPP@SITHU /d/xampp/htdocs/myproj (master)
$ git checkout etc/schema_note
Branch etc/schema_note set up to track remote branch etc/schema_note from origin.
Switched to a new branch 'etc/schema_note'

TPP@SITHU /d/xampp/htdocs/myproj (etc/schema_note)
$ git checkout feature/sampledata
Branch feature/sampledata set up to track remote branch feature/sampledata from
origin.
Switched to a new branch 'feature/sampledata'

TPP@SITHU /d/xampp/htdocs/myproj (feature/sampledata)
$ git checkout fix/cleanup
Branch fix/cleanup set up to track remote branch fix/cleanup from origin.
Switched to a new branch 'fix/cleanup'
Run Code Online (Sandbox Code Playgroud)

这是我的最终回购分支列表:

$ git branch -a
  etc/schema_note
  feature/sampledata
* fix/cleanup
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/etc/schema_note
  remotes/origin/feature/sampledata
  remotes/origin/fix/cleanup
  remotes/origin/master
Run Code Online (Sandbox Code Playgroud)

  • 您最初必须使用 `--single-branch` 或 `--depth` 参数进行克隆以获取该提取行。 (3认同)