Git Commands – 2

Have you ever wanted to copy everything in a particular git repository onto a new git repository including all the commits, branches and mergings etc ? There are certain situations where you would have to do such. This is also known as git mirroring.

Here is a step by step guide to do that

1.Create a bare clone of the old repository.

$ git clone --bare https://github.com/exampleuser/old-repository.git

2.Mirror-push to the new repository.

$ cd old-repository.git
$ git push --mirror https://github.com/exampleuser/new-repository.git

3.Remove the temporary local repository you created in step 1.

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

Now check the new repository and you will see entire git history which was there in old repository is coppied to the new repository with all the branches and commits.