Tracking a single remote branch as a local branch is straightforward enough.
$ git checkout --track -b ${branch_name} origin/${branch_name}
<
In case you already have some branches checked out and want to
you can use the following bash- and zsh-compatible script:
git branch -r | while read b; do if git branch | grep -q " ${b##*/}$"; then git branch --set-upstream ${b##*/} $b; else git branch --track ${b##*/} $b; fi; done
The answer given by Otto is good, but all the created branches will have "origin/" as the start of the name. If you just want the last part (after the last /) to be your resulting branch names, use this:
for remote in `git branch -r | grep -v /HEAD`; do git checkout --track $remote ; done
It also has the benefit of not giving you any warnings about ambiguous refs.
If you want to use powershell and your remote is called origin. Then this works.
git fetch
git branch -r | %{$_ -replace " origin/"} | %{git branch --track $_ "origin/$_"}
Here is my solution of BASH command referring by @tjmcewan:
for remote in `git branch -r | grep -v /HEAD `; do git branch --track ${remote/"origin/"/""}; done
My goal is to solve the problem that all the created branches will have "origin/" as the start of the name, because I tested that $remote variables are still include "origin/":
for remote in `git branch -r | grep -v /HEAD`; do echo $remote ; done
for i in `git branch -a | grep remote`; do git branch --track ${i#remotes/origin/} $i; done
without any scripting (in an empty directory):
$ git clone --bare repo_url .git
$ git config core.bare false
$ git checkout
after that, all remote branches will be seen as local.
original (in russian).