【问题标题】:how to get all branches of my forked git repo如何获取我的分叉 git repo 的所有分支
【发布时间】:2014-11-02 01:13:30
【问题描述】:

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

  • 主人
  • 修复/清理
  • etc/schema_note
  • 特征/样本数据

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

*master  
 remotes/origin/HEAD -> origin/master  
 remotes/origin/master

我试过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?

我也尝试执行 oneliner。

for remote in `git branch -r`; do git branch --track $remote; done

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

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

【问题讨论】:

  • 如果你克隆了 repo,你已经拥有了所有(远程)分支。
  • @VonC 我不认为这是答案,在这里。有问题的远程分支甚至没有在git branch -a的输出中列出...
  • @Jubobs true...一些git fetch 应该更新它。
  • @Jubobs 不是真的,但它很容易测试:克隆一个有很多分支的 repo,然后克隆那个克隆:refs/remotes 命名空间不是克隆。仅限refs/heads

标签: git bitbucket git-branch git-clone


【解决方案1】:

如果您克隆了 repo,您​​应该已经拥有所有远程分支。

git 的工作方式是存储库的每个副本基本相同。克隆存储库的那一刻,您将获得远程服务器拥有的所有内容,包括所有历史记录。

如果您在一个地方看到分支,但在另一个地方看不到(例如,在一个客户端上,但在另一个客户端上没有),那么它只能表示:

  1. 一个位置的本地分支尚未传播到远程服务器

    和/或

  2. 本地客户端尚未获取/拉取传播的更改

编辑

实际上,git namespaces 是否与此处相关?

【讨论】:

    【解决方案2】:

    我最终找到了解决办法。我调整了 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
    

    现在,$ 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
    

    最后,我为每个分支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'
    

    这是我最终的 repo 分支列表:

    $ 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
    

    【讨论】:

    • 您必须最初使用--single-branch--depth 参数进行克隆才能获取该提取行。
    • @onionjake 最初,我遇到了克隆问题。请查看this blog post
    • @onionjake 正是我的情况!
    猜你喜欢
    • 2014-11-19
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    • 2019-05-30
    • 2015-04-24
    • 1970-01-01
    • 2020-03-17
    相关资源
    最近更新 更多