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

Asked

Viewed 621 times

3

I would like to know how to automatically clone all the remote arms to the location, without having to be doing the command below for each.

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

That’s a lot of arms to be able to do it one by one.

3 answers

2


I suggest creating the alias below, which performs the checkout for all remote branches. The name of each branch in place will be equal to 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
  • 1

    This will be very useful to me. Sometimes the mirror repository conflicts with the remote I use for development

  • 1

    I just went through it, Jefferson! So I decided to ask this question and answer!

1

Another way to execute would be by using the command 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 of the current repository.

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

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

If you want to know the details read the post.

1

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

  • Nice you want to help, but you used the reply box to comment. You can post comments when you have a little more reputation points. Please use the answer field only to post a solution to the problem the question deals with.

  • 1

    I gave a solution to his problem, that’s an answer, no?

  • 1

    I changed the answer to keep only the answer. I understand now.

  • 1

    It was worth the downside because of that?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.