回答

收藏

如何在 Git 中克隆所有远程分支

技术问答 技术问答 282 人阅读 | 0 人回复 | 2023-09-12

我有一个master和一个development所有的分支都被推到了GitHub。我已经cloned、pulled 和fetched,但我还是得不到master分支以外的任何东西。0 U* b5 \# f# X( @
我确定我错过了一些明显的东西,但我已经读了手册,但我一点也不高兴。: u7 U. E& ?1 c
                                                                ! S" X8 ^( U! |3 i
    解决方案:                                                               
% l: S* e3 O; I, k, J! n8 c) ~                                                                首先,克隆远程Git存储库并cd到其中:
& W4 P+ e6 N6 }, |$ git clone git://example.com/myproject$ cd myproject接下来,检查仓库中的本地分支:
. M9 ?2 A) O( |6 w* K9 G$ git branch* master但是还有其他分支隐藏在您的存储库中!您可以使用-a查看这些标志:' H( ?* ]; a: z6 x, w8 R7 ?
$ git branch -a* master  remotes/origin/HEAD  remotes/origin/master  remotes/origin/v1.0-stable  remotes/origin/experimental如果只想快速浏览上游分支,可以直接查看:! I6 q9 h5 I+ z7 z" [: B6 u
$ git checkout origin/experimental但如果你想在那个分支工作,你需要创建一个本地跟踪分支,它可以通过以下方式自动完成:) F& j- m& V$ b( ^- P
$ git checkout experimental你会看到4 d6 y7 k0 S$ E- B9 j
Branch experimental set up to track remote branch experimental from origin.Switched to a new branch 'experimental'在这里,新分支只表示该分支是从索引中取出并在当地为您创建的。前一行告诉你,分支正在设置跟踪远程分支,这通常意味着 origin/branch_name 分支。
4 M/ r; U  N! l, D3 G3 A9 B% Q现在,如果您查看当地的分支机构,您将看到以下内容:
8 |; t' |& V& N# E/ A9 G$ git branch* experimental  master其实你可以用git remote.
3 d8 Z8 F3 ]) F# @, E3 Y1 D$ git remote add win32 git://example.com/users/joe/myproject-win32-port$ git branch -a* master  remotes/origin/HEAD  remotes/origin/master  remotes/origin/v1.0-stable  remotes/origin/experimental  remotes/win32/master  remotes/win32/new-widgets在这一点上,事情变得非常疯狂,所以运行gitk看看发生了什么:) N, ?9 ^% S6 `. Y5 O9 ~
$ gitk --all &
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则