How Do I Clone All Remote Branches?

Better Stack Team
Updated on June 24, 2024

To clone all remote branches from a Git repository, you can use the --mirror option with git clone. Here's how you can do it:

 
git clone --mirror <repository-url>

Replace <repository-url> with the URL of the Git repository you want to clone.

This command will create a bare repository on your local machine that contains all remote branches, tags, and commits from the original repository.

Once you have cloned the repository, you can navigate into it and convert it to a regular repository by removing the --mirror option.

 
cd <repository-name>
git config --unset core.bare

This converts the cloned repository from a bare repository to a regular repository, allowing you to work with it as usual.

Note:

  • Cloning all remote branches can result in a large repository size, especially if the repository has many branches and commits. Make sure you have enough disk space available.
  • If you only need to clone specific branches, you can use the -single-branch option followed by the branch name when cloning the repository. This will only clone the specified branch and its history.
  • Be mindful of the repository's size and your network bandwidth when cloning large repositories.
Got an article suggestion? Let us know
Explore more
Git
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github