Open In App

What is Git Clone?

Last Updated : 23 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Git, a distributed version control system, is widely used for tracking changes in source code during software development. One of the fundamental commands in Git is git clone. This command is important for developers to collaborate on projects by allowing them to create a local copy of a remote repository. In this article, we will explore what git clone is, how it works, and the various options and best practices associated with it.

What is Git Clone?

The git clone command creates a copy of an existing Git repository. This repository can be hosted on platforms like GitHub, GitLab, or Bitbucket, or it can reside on a local or remote server. Cloning a repository involves copying all the repository’s data to your local machine, including the entire history and all branches.

Syntax:

git clone <repository-link>

For Example: If you want to clone the Bootstrap repository, you would run

git clone https://github.com/twbs/bootstrap.git
GitHub Repository URL
What is Git Clone?

In the above image, It’s a Bootstrap repository and you want to clone it in your local system. For this, you have to use the link to clone this repository on your computer. First, you have to go inside the folder in which you want to clone the repository, for this use the cd command

Git Branch
What is Git Clone?

After that, Clone the repository using git clone <repo-link>

git clone https://github.com/twbs/bootstrap.git
Git clone repo link
What is Git Clone?

The cloning process will begin. You’ll see progress messages indicating how much of the repository has been cloned (e.g., 14%, 50%, 100%).

Clonning the repository

Once the cloning process is complete, you can navigate into the new directory (e.g., cd bootstrap) to start working on the project locally.

git log

If you need to stop the cloning process before it finishes, you can press Ctrl + C to cancel the operation.

Terminate the proceses

By cloning a repository, you get a complete copy of the project, including all of its branches and commit history, allowing you to work offline and push your changes back once you are ready.

Git Clone With Username And Password

If you are cloning a repository using HTTPS, you may need to authenticate with your GitHub (or other Git hosting services) username and password. You can pass the credentials directly in the URL like this:

git clone https://username:[email protected]/username/repository.git

In the place of "Username" and "Password" give your credentials.

Important: For security reasons, it is not recommended to include your password in the URL. Instead, you should use a credential manager or access tokens for more secure authentication.

Cloning a Specific Branch

By default, git clone clones the main branch (often named main or master) of a repository. However, if you want to clone a specific branch of the repository, you can use the -b option.

Syntax:

git clone -b <branch-name> <repository-url>

This command clones the specified branch into your local repository instead of the default branch.

Repo-to-Repo Collaboration

Cloning repositories is a key part of collaborating on projects with other developers. When you clone a repository, you create a local copy where you can make changes. Afterward, you can push your changes back to the remote repository for others to review and merge.

To clone the remote repository use the following command.

git clone <remote_repository_url>

This creates a working copy of the project, allowing you to modify it, and then push the updates back to the repository.

Git Clone -Branch

The git clone --branch command is used to clone a specific branch from a remote Git repository to your local machine. By default, when you clone a repository, it clones the main branch (usually called main or master). However, if you want to clone a different branch, you can specify the branch name in the command.

git clone --branch <branch_name> <remote_repository_url>
  • <branch_name>: This is the name of the branch you want to clone from the remote repository.
  • <repository_url>: This is the URL of the remote repository (either HTTPS or SSH).

For example, if you want to clone the feature-xyz branch from a repository, you would run the following command:

git clone --branch feature-xyz https://github.com/username/repository.git

Git Clone - Mirror vs Git Clone - Bare

Git supports two specialized cloning methods: mirror cloning and bare cloning.

1. Git Clone - Mirror:

  • A mirror clone creates a complete, exact copy of a remote repository, including all refs, branches, and configuration.
  • Use Case: Typically used for creating full backups of repositories.
git clone --mirror <repository-url>

2. Git Clone - Bare:

  • A bare clone only contains the repository’s version control data (e.g., .git folder) and doesn't include the working directory (the actual files). It’s commonly used for shared repositories.
  • Use Case: Often used for creating a central repository for collaboration or setting up a server repository.
git clone --bare <repository-url>

Git Clone -Mirror vs. Git Clone -Bare

Git Clone -Mirror

Git Clone -Bare

Git Clone -Mirror create an complete copy of the git remote repository or complete mirror of the git repository.

Git Clone -Bare will only copies the file which are required for the keeping the track of that repository.

Git Clone -Mirror it will have the all the copies of the files which are exactly present in the remote git repository.

Git Clone -Bare will only keeps the files which are necessary to keep the track.

Mostly used for the backup purposes

Mostly used for the continuous integration.

It can also be used for the offline development purpose.

It can also be used for the working on the same repository on multiple locations.

Git URLs for Cloning

The code which is stored in the git remote repositories are need to be accessed or to be cloned in to the local repositories for that git URL's will acts as an git web address.

Types of Git URL's

1. HTTPS URL: Commonly used for cloning and pushing code.

Example: https://github.com/username/repository.git

2. SSH URL: More secure and used for authentication without entering a username or password.

Example: [email protected]:username/repository.git

3. Git Protocol URL: Less commonly used but works similarly to HTTP.

Example: git://github.com/username/repository.git

4. Local File System: Clone from a local directory.

Example: /path/to/repository

5. Relative File System: For local repository paths relative to the current directory.

6. Git Bundle: A packaged archive of a Git repository.

Cloning a Repository into a Specific Local Folder

You can specify the local directory where you want the repository to be cloned. Use the following command to clone a repository into a specific folder:

Syntax

git clone <repository-url> <local-folder-name>

Replace the URL with the repository URL you want to clone, and specify the name of the folder where you want to copy the repository in place of <local_folder>.

For example, to clone a repository into a folder named my-project, use:

git clone https://github.com/username/repository.git my-project

Conclusion

Git’s clone command is a powerful feature for starting new projects, collaborating on existing ones, and managing multiple versions of your code. Whether you are contributing to open-source projects or working on a team project, cloning allows you to work on code locally and sync it with others. By understanding how to use git clone efficiently, you can improve collaboration, version control, and overall productivity in your development workflow.


Next Article
Article Tags :

Similar Reads