When git clone some repository then it retrieves all branches from it:
git clone https://github.com/android/platform_build.git build1
cd build1/ && git branch -a && cd ..
then, when I use build1 as a mirror and clone it, I do not see all its remote branches (I see only build1's local master branch)
git clone build1 build2
cd build2 && git branch -a && cd ..
How can I checkout remote of remote branches ?
I know that I can checkout all remote branches in build1 mirror with command
cd build1 && for remote in `git branch -r `; do git branch --track $remote; done
Track all remote git branches as local branches but what if I do not have access to build1 directory ?
Also, there is git ls-remote origin command which shows all remote refs, but is there any elegant way to checkout those remote of remote branches ?
After you clone
build1tobuild2,build1isbuild2'sorigin, andbuild2knows nothing abouthttps://github.com/android/platform_build.git, which is where the "remote" branches live. One solution may be to addhttps://github.com/android/platform_build.gitas a remote in the configuration ofbuild2. To add a remote calledgithub:Then run a
fetchto get the remote branches:Now, when you run
git branch -ayou should see branches prefixed withremotes/github/that correspond with those prefixed withremotes/origininbuild1.On the other hand,
build2should have a remote branch for each local branch inbuild1, including those that are tracking remote branches frombuild1's perspective. For example, if there is a branch namedfooon github, it will show up asremotes/origin/fooinbuild1. If you set up a local branch to track that remote branch inbuild1also calledfoo, thenbuild2should have aremotes/origin/fooas well. Then, whenfoois updated inbuild1by fetching/merging changes from github'sfoo, those changes should show up inbuild2after afetch/pull.