GIT Backup/Duplicating a repository

Mirroring a repository

  1. Open Git Bash/command line client.

  2. Create a bare clone of the repository. by using --bare option

    git clone --bare https://username@orgurl/old-repository.git
  3. Mirror-push to the new repository.

    cd old-repository.git
    git push --mirror https://username@orgurl/new-repository.git
    
  4. Remove the temporary local repository you created in step 1.

    cd ..
    rm -rf old-repository.git
    

    Mirroring a repository in another location

    If you want to mirror a repository in another location, including getting updates from the original, you can clone a mirror and periodically push the changes.

    1. Open Git Bash/command line client.

    2. Create a bare mirrored clone of the repository.

      git clone --mirror https://username@orgurl/repository-to-mirror.git
    3. Set the push location to your mirror.

      cd repository-to-mirror.git
      git remote set-url --push origin https://sername@orgurl/mirrored

    As with a bare clone, a mirrored clone includes all remote branches and tags, but all local references will be overwritten each time you fetch, so it will always be the same as the original repository. Setting the URL for pushes simplifies pushing to your mirror. To update your mirror, fetch updates and push.

    git fetch -p origin
    git push --mirror
    
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.