gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 14:38:15 24 4
gpt4 key购买 nike

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

  • 大师
  • 修复/清理
  • etc/schema_note
  • 特征/样本数据

enter image description here

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

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

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

error: pathspec 'origin/fix/cleanup` did not match any file(s) known to 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 个分支。我的 repo 发生了什么?

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

最佳答案

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

关于git - 如何获取我 fork 的 git repo 的所有分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25730667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com