Git Hub Clone All Branches At Once

This isn't too much complicated, very simple and straight forward steps are as follows:

After cloning the repo, run $ cd myproject

git branch -a This will show you all the remote branches.

$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/v1.0-stable
  remotes/origin/experimental

If you want to work on remote branch, you'll need to create a local tracking branch:

$ git checkout -b experimental origin/experimental

Verify whether you are in the desired branch by the following command;

$ git branch

The output will like this;

*experimental
master
some branch2
some branch3 

Notice the * sign that denotes the current branch.


git clone --bare <repository url goes here> .git

Then after the repo is clone with all its branches then do the following

git config --bool core.bare false

git reset --hard

(1) Inside git local repostitory, create a new sh file

touch getAllBranches.sh
vi getAllBranches.sh

(2) Insert the below content to getAllBranches.sh file:

for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
   git branch --track ${branch#remotes/origin/} $branch
done

(3) Get all branches:

chmod +x getAllBranches.sh    
sh getAllBranches.sh

(4) Check result at local repository:

git branch

For example, I use repository: https://github.com/donhuvy/spring-boot

As you can see, I have fetched all branches to local machine:

enter image description here

Tags:

Git

Github