How to duplicate a Git repository? Repository mirroring simplified.

How to duplicate a Git repository? Repository mirroring simplified.

To duplicate a repository without forking it, you can run a special clone command, then mirror-push to the new repository.

Before you can duplicate a repository and push to your new copy, or mirror, of the repository, you must create the new repository on PWSLab. In these examples, exampleuser/new-repository or exampleuser/mirrored are the mirrors.

Mirroring a Repository 

Step 1: Open Terminal/Git Bash.
Step 2: Create a bare clone of the Repository. 
$ git clone --bare https://example.pwslab.net/exampleuser/old-repository.git
Step 3: Mirror-push to the new repository.
$ cd old-repository.git 
$ git push --mirror https://example.pwslab.net/exampleuser/new-repository.git
Step 4: Remove the temporary local repository you created in Step 1.
$ cd .. 
$ rm -rf old-repository.git

Mirroring a repository that contains Git Large File Storage objects

Step 1: Open Terminal.
Step 2: Create a bare clone of the repository. Replace the example username with the name of the person or organization who owns the repository, and replace the example repository name with the name of the repository you'd like to duplicate. 
$ git clone --bare https://example.pwslab.net/exampleuser/old-repository.git 
Step 3: Navigate to the repository you just cloned. 
$ cd old-repository.git 
Step 4: Pull in the repository's Git Large File Storage objects. 
$ git lfs fetch --all
Step 5: Mirror-push to the new repository. 
$ git push --mirror https://example.pwslab.net/exampleuser/new-repository.git
Step 6: Push the repository's Git Large File Storage objects to your mirror. 
$ git lfs push --all https://example.pwslab.net/exampleuser/new-repository.git
Step 7: Remove the temporary local repository you created in Step 1. 
$ cd .. 
$ rm -rf old-repository.git
These steps are helpful to migrate Git repositories from Git Platforms like GitHub, Bitbucket or GitLab. 


Have more questions? Please email us at support@peerxp.com
Also, let us know if the article is helpful!

    • Related Articles

    • Simple steps to synchronise a Remote Fork in a Git repository

      Introduction When you collaborate in any upstream project (like an open-source project) it is likely to be asked to make a fork of the main repository. A fork is a copy of the project in your Git account. This duplicate allows you to freely ...
    • How To Change Git Remote URL?

      Introduction Git remote is a pointer that refers to another copy of the repository that is usually hosted on a remote server. In some situations, like when the remote repository is migrated to another host, you need to change the remote’s URL. This ...
    • Mirroring PWSLab Repositories to GitHub, Bitbucket and GitLab or any Git repositories

      Introduction Repository mirroring allows for mirroring of repositories to external sources. It can be used to mirror branches, tags, and commits between repositories. A repository mirror at PWSLab will be updated automatically. You can also manually ...
    • How to apply Git Patches?

      Patch is a text file, whose contents are similar to Git diff, but along with code, it also has metadata about commits; e.g., commit ID, date, commit message, etc. We can create a patch from commits and other people can apply them to their repository. ...
    • PWSLab Git Workshop - Useful commands and concepts

      Agenda A brief history of Git. PWSLab walkthrough. Configure your environment. Workshop. Git Introduction Visit: https://git-scm.com/about Distributed version control. It does not rely on a connection to a central server. Many copies of the complete ...