How to Duplicate a Git Repository or Mirror a Repository

Updated on June 26, 2020

One way of duplicating a repository is by forking it -to do that, browse to the repository you wish to duplicate, and click the “Fork” button. The other way to duplicate a Git repository is without forking it by executing a mirror-push command to the newly created repository. In this tutorial, I’ll be explaining how to duplicate a Git Repository without forking it – that’s via mirror-push command.

First create a repository

Before you can duplicate a repository, you should create one on GitHub. To do that, login to GitHub and click on “New” button to create a new repository.

Duplicate a Git Repository

In order to execute Git commands, you need to download Git Bash and install it. Once done,

Step 1: Launch Git Bash

Step 2: Let’s create a bare clone of the repository that you wish to duplicate

git clone --bare https://github.com/username/repo-you-wish-to-duplicate.git

Step 3: Duplicate a repository using mirror push command, to do that you need to change directory to the bare-cloned repository folder.

cd repo-you-wish-to-duplicate.git

Now, mirror or duplicate the repository using the below command.

git push --mirror https://github.com/username/duplicate-repository.git

That’s it! Go to your GitHub account and view the duplicate repository.

Step 4: Well, you don’t need the bare-cloned repository in the local machine, so just go ahead and delete it.

Do you see Repository not found error while pushing the code change? Well, here are a few suggestions to help fix the issue.

Was this article helpful?

Related Articles

Comments Leave a Comment

  1. Hey David, for me this error appears on the end of the proccess:
    “remote: GitLab: You are not allowed to force push code to a protected branch on this project.
    To https://gitlab.com/myreposiroty/client-cms-teste-duplicated.git
    ! [remote rejected] main -> main (pre-receive hook declined)
    ! [remote rejected] featured-teste -> featured-teste (pre-receive hook declined)
    error: failed to push some refs to ‘https://gitlab.com/myreposiroty/client-cms-teste-duplicated.git'”

    Did you know what happens here?

Leave a Comment