2012-05-14 156 views
4

當混帳克隆一些版本庫,那麼它會檢索所有分支從中:的Git檢出遠程分支

git clone https://github.com/android/platform_build.git build1 
cd build1/ && git branch -a && cd .. 

然後,當我使用build1如鏡和克隆它,我沒有看到它的所有遠程分支機構(我只看到build1的本地主分支機構)

git clone build1 build2 
cd build2 && git branch -a && cd .. 

如何結帳遠程分支機構?

我知道我可以檢出所有遠程分支機構build1中鏡子命令

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

Track all remote git branches as local branches 但是如果我沒有獲得build1中的目錄?

此外,有git ls-remote origin命令,它顯示所有的遠程參考,但有沒有優雅的方式來檢查遠程分支的遠程?

+0

我可以用'git://'來代替'https://'嗎?提取對於您和服務器來說都更有效率。 – jthill

回答

1

後您克隆build1build2build1build2origin,並build2一無所知https://github.com/android/platform_build.git,這是‘遠程’分支住的地方。一種解決方案可能是將https://github.com/android/platform_build.git作爲build2的配置中的遠程設備。要添加遠程叫github

git remote add github https://github.com/android/platform_build.git 

然後運行一個fetch獲得遠程分支:

git fetch github 

現在,當你運行git branch -a你應該看到remotes/github/與這些前綴對應前綴分行remotes/origin in build1

在另一方面,build2應該在build1爲每個本地分支遠程分支,包括那些從build1的角度跟蹤遠程分支。例如,如果在github上有一個名爲foo的分支,它將在build1中顯示爲remotes/origin/foo。如果您在build1(也稱爲foo)中設置本地分支以跟蹤該遠程分支,那麼build2也應具有remotes/origin/foo。然後,當foo通過從github的foo獲取/合併更改而在build1中更新時,那些更改應該在fetch/pull之後的build2中顯示。