How to clone the repository and all the arms of the remote?

3

I would like to know how to automatically clone all the remote's arms to the location, without having to do the command below for each one.

git checkout -b <branch> <remote>/<branch>

There are many arms to be able to do this one by one.

    
asked by anonymous 07.06.2017 / 19:23

3 answers

2

I suggest creating the alias below, which performs the checkout for all the remote branches. The name of each branch in place will be the same as the remote branch.

git config --global alias.clone-branches '! git branch -a | sed -n "/\/HEAD /d; /\/master$/d; /remotes/p;" | xargs -L1 git checkout -t'

Created the alias, just run it like this:

git clone-branches
    
07.06.2017 / 19:23
1

Another way to run would be by using the git ls-remote

This command lists the references of the remote repository, for example:

git ls-remote --heads origin

The return will be the list of remots in the current repository.

Using a simple command line in Powershell you can download the branches:

git ls-remote --heads origin | % { $_ -match 'refs/heads/(.*)' | out-null; $matches[1] } | % { git checkout $_ }

If you want to know the details, read the post .

    
15.07.2017 / 23:54
1

git clone <repo> and then a git fetch origin (or any name you've given). So your location has all branchs from the remote.

    
16.07.2017 / 01:12