How can I keep two git repository synced?
The first repository is a "central" repository used by the team to push changes, created following the git book guide. The second repository will be only a mirror of the first.
I'm using git with ssh and changes should be pushed only from the first repository since it is behind a secured network.
Assuming the first repository knows about its mirror, you can use a post-receive
hook. According to the manual, one of the common uses of such a hook is to notify others of a successfully received update.
To create such a hook, put a script (any script, the language/interpreter is determined by the shebang at the top) named post-receive
in your hooks
folder under .git
(or under the main repo if it is bare). In the hook, run a command to push to the remote you are interested in. A sample script could be as follows:
#!/bin/sh
git push mirror
Here, mirror
is the name of the mirror remote as configured in the main repository.