#!/bin/bash
# Clones as usual but creates local tracking branches for all remote branches.# To use, copy this file into the same directory your git binaries are (git, git-flow, git-subtree, etc)
clone_output=$((git clone "$@" ) 2>&1)retval=$?echo $clone_outputif [[ $retval != 0 ]] ; thenexit 1fipushd $(echo $clone_output | head -1 | sed 's/Cloning into .\(.*\).\.\.\./\1/') > /dev/null 2>&1this_branch=$(git branch | sed 's/^..//')for i in $(git branch -r | grep -v HEAD); dobranch=$(echo $i | perl -pe 's/^.*?\///')# this doesn't have to be done for each branch, but that's how I did it.remote=$(echo $i | sed 's/\/.*//')if [[ "$this_branch" != "$branch" ]]; thengit branch -t $branch $remote/$branchfidonepopd > /dev/null 2>&1
Grab everything that inside the current folder and create all the branches on the local machine, therefore making this a normal repo.
$ git reset --hard
So now you can just type the command git branch and you can see that all the branches are downloaded.
This is the quick way in which you can clone a git repository with all the branches at once, but it's not something you wanna do for every single project in this way.
$ git remote update //This will update your local$ git branch -a //This will list all the branches(After updating you can nowsee the new branch in the list)$ git checkout your_branch_name