Git is undoubtedly a popular version control system. When you adopt the best practices in Git, it turns into a potent and flexible tool. In this answer, you will learn what Git mirroring is and why you need it. I will also share a step-by-step guide for Git mirroring.
Before we delve into more details, let’s see why you need Git mirroring.
You can start a project privately and decide to open-source it on GitHub later on.
Let’s try another example where you want to upgrade your repository server or try and move your Git repo between two servers without losing its history, branches, etc.
Git mirroring
can help you answer these questions.
Git mirroring is when a mirror copies the
git clone --mirror old_repo_url destination_repo
In simple words, it will do the following:
Its a four-step process – I will explain the step-by-step procedure of how you can do that.
The first step is straightforward. You have to mirror the Git repository to your local machine. You can use this command:
git clone --mirror <source_repo_url>
So, the above Git command will create a directory with your repository name.
Now, you can create a new repository on your destination server. You can use any name on the destination server, but it helps to use the same name (for simplicity).
It is time to set the new server URL in your Git repo. You can run the command from inside your git repository folder:
git remote set-url --push origin <destination_repo_url>
Time to push your repository:
git push --mirror
By running the above Git command, you are pushing the complete Git repository with all its Commit history and Branches.
With the Git Mirror option, you can save your valuable commit history with other important refs and remote-tracking branches.
The days are gone when developers would manually copy the code from one server to another.
I hope this simple answer helps you.
Free Resources