【Git】Duplicate a Git Repo

Posted by 西维蜀黍 on 2020-09-07, Last Modified on 2021-10-17

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

Mirroring a repository

  1. Open Terminal.

  2. Create a bare clone of the repository.

    $ git clone --bare https://github.com/exampleuser/old-repository.git
    
  3. Mirror-push to the new repository.

    $ cd old-repository.git
    $ git push --mirror https://github.com/exampleuser/new-repository.git
    
  4. Remove the temporary local repository you created earlier.

    $ cd ..
    $ rm -rf old-repository.git
    

Reference