How do I pull all of the remote branches to my own repository?
if I type:
git branch -a
I get a long list of branches, but if I type:
git branch
I see only 2 of them.
How do I pull ALL branches into my local list?
I know I can do:
git checkout --track origin/branch-name
but that pulls and checks out only one branch at a time. Any way to get it all done at once without that whole tedious work of running git checkout --track origin/branch-name over and over and over again?
ps. I tried following commands, none of them made remote branches appear in my git branch list:
git fetch --all git remote update git pull --all
git pull fetches updates for all local branches, which track remote branches, and then merges the current branch.
To get all the changes from all the branches, use git fetch --all . And if you'd like to clean up some of the branches that no longer exist in the remote repository, git fetch --all --prune will do the cleaning up!
The command I usually use to make all visible upstream branches, and tracking them is detailed in "Track all remote git branches as local branches":
remote=origin ; for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^\/]+\//,"",$1); print $1}'`; do git branch --set-upstream-to $remote/$brname $brname ; done
Or:
remote=origin ; for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^\/]+\//,"",$1); print $1}'`; do git branch --track $brname $remote/$brname ; done
For more readability:
remote=origin ; // put here the name of the remote you want for brname in ` git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^\/]+\//,"",$1); print $1}' `; do git branch --set-upstream-to $remote/$brname $brname; # or git branch --track $brname $remote/$brname ; done
The second one is for creating new local branches tracking remote branches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With