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.