What would be the best way to set up a read-only git mirror of an existing svn repository, and set up post-commit hooks such that whenever someone commits to svn, the git mirror is automatically updated? Mainly, I'd like to run git-svn clone just once, on the server, and then let people just check out from git without having to git-svn clone the entire svn repository themselves.
Asked
Active
Viewed 3,689 times
2 Answers
4
I do that on a project that uses SVN (pushing to a public repository on github). I don't have a SVN commit hook, but this on a cron job:
#!/bin/bash
repo=/path/to/my-mirror.git
lockfile="$repo/cron-lock"
if ! lockfile -r1 "$lockfile";then
exit 1
fi
export GIT_DIR=$repo
# update refs/remotes/git-svn:
git svn fetch -q
# make 'master' match the git-svn branch:
git fetch "$repo" refs/remotes/git-svn:refs/heads/master
# publish to github
git push github master
rm -f "$lockfile"
If you trigger this from a SVN commit hook instead of a cron job, it should work.
Of course, you need to set up a remote called github
using git remote add github [...]
. The git repository I am using is a "bare" repository (see git init --bare
).

ehabkost
- 411
- 3
- 5
2
The best way to set up an Svn/Git mirror (writable) would be to use SubGit - this is a tool specifically developed for this task. Disclaimer: I am the developer of this tool.

elixenide
- 44,308
- 16
- 74
- 100

Alexander Kitaev
- 695
- 6
- 8
-
1Besides, SubGit 2.0 no longer needs local access to the Subversion repository and could build a writable Git mirror of a remote Subversion repository too (see http://subgit.com/eap). – Alexander Kitaev Nov 26 '12 at 21:48
-
2@AlexanderKitaev Please note that you must disclose your affiliation when linking to a product or another website. I see from [this post](http://stackoverflow.com/a/13288270/2057919) that you developed SubGit. I have edited this answer to reflect that. In the future, please be sure to mention your connection if you link to SubGit. – elixenide Jan 19 '16 at 18:03