This is a post that details on how to sync a subversion repository to git repository on github.com, and how to keep it in sync.
The following sites were instrumental in getting this to work:
There are a number of steps to take. From a bird’s eye view:
git svnto clone the
svnrepo to a
- Create a github
- Add a remote origin in your local git to the remote github repo;
- Use some SSH foo to use a separate SSH key for pushing to github.com.
- We are working with the fictional svn repo located at
Clone the repository
mkdir github.com cd github.com git svn clone -s https://svn.example.net/example
Create github repo
Go to the github.com’s website and create a new repository, in this case we’ll use my username (
So the github.com’s repository is:
Add a remote in (local) git
git remote add origin firstname.lastname@example.org:miekg/example.git
And push the contents to the remote (i.e. github):
git push origin master
And voila. You have a git repository from a cloned svn repository.
Keeping it in sync
Ideally you want to run a cronjob to keep this repository in sync with the subversion repository. The git commands used are trivial:
git svn rebase git push
However the ssh key you’re using has a passphrase. An idea is to use a separate key (without a passphrase) just for this repository. Sadly it is not possible to restrict a ssh key to a specific repository, so this new, passphrase-less key can be used to update all your repositories.
But still this can be useful, so how do you set this up?
- First create a new key pair:
ssh-keygen -f github.com.
Host example.github.com HostName github.com User git IdentityFile ~/.ssh/github.com
Use the “fake” host (
example.github.com) as the remote branch in git:
git remote add origin example.github.com:miekg/example.git
If you already added the remote you can just edit
.git/configand make the change there.
git pushwill now use the ssh-server
example.github.com, the user
gitand the identity file
~/.ssh/github.comand will not prompt for a passphrase.
Dealing with changes/patches
The hard part is getting changes made in this git repository back upstream (in the origin subversion repository). You can do this with git, but it gets complicated (IMHO).
A simpler idea is just to not touch this git repository, but fork it, make your changes there and send the patch to the maintainer of the subversion repository. The git repository then gets synchronized again (hopefully with your changes).