I am developing an application and I push my code towards a Git server. I know that even if my server breaks I can continue to commit locally and when the server is repaired I can push all of my code towards it. But I want a spare server that is a mirror of the main server. Is it possible, with Git, to have 2 servers (or n servers) with the same data? I want that when I push to a server it automatically replicates itself to the other server.
Asked
Active
Viewed 30 times
-1
-
2Please explain for what reason a Google search does not answer your question. I found [git-mirror](https://www.ralfj.de/projects/git-mirror/) for example. – Tim Nov 28 '19 at 16:37
-
Now I check it out. I hadn't found that page in my searches. – nix86 Nov 28 '19 at 16:40
-
But I haven't understood what is gitolite. I mean I have installed a git server on my own. I don't have github or gitlab. – nix86 Nov 28 '19 at 16:45
1 Answers
1
Short answer: yes
Longer answer: the implementation will depend on what is the target for the "master" and "mirror" servers.
I personally use gitlab-ce push mirroring every day with my own company server to automatically push the code I commit "locally" to my client's git server.
For a very light implementation, you could create a post-receive hook on ServerA which git push --mirror serverB
. See this other answer for more details.
That's only two of the many possibilities. You would need to give much more details for an on spot answer (and that might become totally off topic for Stack Overflow).

Zeitounator
- 38,476
- 7
- 53
- 66
-
I want that when I push to a server it automatically replicates itself to the other server. – nix86 Nov 28 '19 at 16:37
-
This is what I just described above for gitlab. If you don't give information about your "git server", no one will be able to correctly help you. And as said in my answer, this becomes off topic for SO (it's not a coding related issue). Try SuperUser or ServerFault which are better suited. – Zeitounator Nov 28 '19 at 16:42
-
@nix86 added a second general possibility that might better suit your needs given one of your above comments. Hope it helps. – Zeitounator Nov 28 '19 at 17:10