Git

What’s the Difference Between git clone –mirror and git clone

To build a connection between the local machine and the remote hosting service, developers are required to clone the remote repository to the local repository. Additionally, when connections get established, they can access a remote repository list of the content to get up-to-date with the latest version that can be modified by the other project’s team members.

There are different scenarios for cloning remote repositories. For instance, only clone the current tracking branch content or all the extended references or any other case.

The outcomes from this blog are:

Difference Between git clone –mirror and git clone Commands

The “$ git clone <remote-url>” command is used to clone the project files that are being tracked into Git or where developers perform the commands. In contrast, the “$ git clone –mirror <remote-url>” command will clone all the extended references on the mirror and overwrite the remote repository with the local branches (local references).

How to Clone Repository Using “$ git clone” Command?

To build a connection by cloning a Git remote repository using the “$ git clone” command, first, we will navigate to the Git local repository and execute the “$ git clone <remote-url>” command. Then, push the remote URL and download the updated remote repository.

Let’s move forward and implement the given scenario.

Step 1: Navigate to Git Repository

Use the “cd” command to move to the required local repository:

$ cd "C:Users\nazma\Git\Test_5"

Step 2: Clone Repository

Now, run the provided command to connect the remote repository with the local repository:

$ git clone https://github.com/GitUser0422/demo.git

Step 3: Push Local Repository

To push the local repository content into the remote repository, run the “git push” command along with the remote URL:

$ git push https://github.com/GitUser0422/demo.git

Step 4: Download Update Remote Repository

Lastly, download the updated version of the remote repository using the “git remote” command with the remote and local branch name:

$ git fetch alpha master

According to the below-provided output, the specified remote branch is fetched successfully:

How to Clone Repository Using “$ git clone –mirror” Command?

When the developers want to clone the remote repository along with the targeted local branches, including remote branches, and set them up as a reference configuration, they can create a mirror copy with the help of the “–mirror” option in the git clone command.

Follow the instruction below to clone a Git remote repository with the “–mirror” option.

Step 1: Clone Remote Repository With “–mirror” Option

Run the “git clone” command to the local repository with the “–mirror” option:

$ git clone --mirror https://github.com/GitUser0422/demo5.git

As a result, all the extended references of the remote repository and the remote branches tracking configuration will be maintained:

Step 2: Git Push With “–mirror” Option

Next, push all local changes into the remote repository through the provided command:

$ git push --mirror https://github.com/GitUser0422/demo5.git

Step 3: Fetch Updated Remote Repository

Lastly, execute the git fetch“ command to update the local repository with the new version of the remote repository:

$ git fetch origin master

That’s all! We have explained the difference between the “git clone” and “git clone –mirror” commands.

Conclusion

If developers need to clone all the extended references on the mirror and overwrite the remote repository with the local branches (local references), the “$ git clone –mirror” command can be utilized. However, the “$ git clone” command is used to clone the development project files that are being tracked into Git or where developers perform the commands. This post demonstrated the difference between the “git clone” and “git clone –mirror” commands.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.