簡體   English   中英

遠程存儲庫的Git checkout遠程分支

[英]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克隆到build2build1build2origin ,而build2https://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/為前綴的分支,這些分支對應於build1remotes/origin為前綴的build1

另一方面, build2應該為build1每個本地分支設置一個遠程分支,包括那些從build1的角度跟蹤遠程分支的分支。 例如,如果在github上有一個名為foo的分支,它將在build1顯示為remotes/origin/foo 如果你設置一個本地分支來跟蹤build1也稱為foo遠程分支,那么build2應該有一個remotes/origin/foo 然后,當foo在更新build1通過獲取/合並來自GitHub的變化foo ,這些變化應該出現build2fetch / pull

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM