Cloning all remote branches with Git

Published at 2013-09-27 11:17:16

The process to get all of the branches in your Git repository checked out locally should be a simple task, right?

Wrong.

According to the accepted and most popular answer to this question on Stackoverflow (about as authoritative as Wikipedia these days), you need to run a shell script to achieve this:

How to fetch all git branches: top answer

It gets worse, just look at some of the answers in another related question here, everything from multiple Git commands, shell scripts, and Ruby scripts wrapping the Git CLI:

How do I clone all remote branches with Git?

It boils down to the following five commands:

mkdir myrepo
cd myrepo
git clone --bare user@hostname:/path/to/myrepo.git .git 
git config core.bare false
git reset --hard

Now when you run git branch, you should see all of the branches checked out locally.

............................................________........................ 
....................................,.-‘”...................``~.,.................. 
.............................,.-”...................................“-.,............ 
.........................,/...............................................”:,........ 
.....................,?......................................................\,..... 
.................../...........................................................,}.... 
................./......................................................,:`^`..}.... 
.............../...................................................,:”........./..... 
..............?.....__.........................................:`.........../..... 
............./__.(.....“~-,_..............................,:`........../........ 
.........../(_....”~,_........“~,_....................,:`........_/........... 
..........{.._$;_......”=,_.......“-,_.......,.-~-,},.~”;/....}........... 
...........((.....*~_.......”=-._......“;,,./`..../”............../............ 
...,,,___.\`~,......“~.,....................`.....}............../............. 
............(....`=-,,.......`........................(......;_,,-”............... 
............/.`~,......`-...............................\....../\................... 
.............\`~.*-,.....................................|,./.....\,__........... 
,,_..........}.>-._\...................................|..............`=~-,.... 
.....`=~-,_\_......`\,.................................\........................ 
...................`=~-,,.\,...............................\....................... 
................................`:,,...........................`\..............__.. 
.....................................`=-,...................,%`>--==``....... 
........................................_\..........._,-%.......`\............... 
...................................,<`.._|_,-&``................`\..............