[英]Git checkout remote branch of a remote repository
當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
跟蹤所有遠程git分支作為本地分支但是如果我沒有訪問build1目錄怎么辦?
此外,還有git ls-remote origin
命令顯示所有遠程引用,但是有沒有優雅的方法來檢查遠程分支的遠程?
在將build1
克隆到build2
, build1
是build2
的origin
,而build2
對https://github.com/android/platform_build.git
一無所知,這是“遠程”分支所在的位置。 一種解決方案可能是在build2
的配置中將https://github.com/android/platform_build.git
添加為遠程。 要添加名為github
的遠程:
git remote add github https://github.com/android/platform_build.git
然后運行fetch
來獲取遠程分支:
git fetch github
現在,當你運行git branch -a
你應該看到以remotes/github/
為前綴的分支,這些分支對應於build1
以remotes/origin
為前綴的build1
。
另一方面, build2
應該為build1
每個本地分支設置一個遠程分支,包括那些從build1
的角度跟蹤遠程分支的分支。 例如,如果在github上有一個名為foo
的分支,它將在build1
顯示為remotes/origin/foo
。 如果你設置一個本地分支來跟蹤build1
也稱為foo
遠程分支,那么build2
應該有一個remotes/origin/foo
。 然后,當foo
在更新build1
通過獲取/合並來自GitHub的變化foo
,這些變化應該出現build2
后fetch
/ pull
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.