Git Mirroring
intro
git mirroring is a process of replicating a repository from one location to another one. to ensure
that there are multiple copies of the repository available for use when needed.
these mirrors can be used as backups, or to ensure accessing repositories easily for large
distributed teams.
of course, git mirroring can be done manually by copying the repo files to other locations,
but this approach will make it difficult to keep the copies in sync.
steps
- create an empty repository at the destination location
- in source repo:
git remote add mirror git://example.com/mirror.git
- then to verify that the reference has been added
git remote -v
- and push
git push --mirror mirror
git hooks
finally, we can use git push --mirror mirror
to push changes to the mirror from the original repo
, but if we want to make this process happen automatically when we push changes to the src, we can
use git hooks :
inside the SRC/.git/hooks/
create a file called post-commit
and put the following code in it:
git push --mirror mirror
and make it executable
chmod +x mirroring.sh