Git – Is it possible to have a Subversion repository as a Git submodule


Is there a way to add a Subversion repository as a Git submodule in my Git repository?

Something like:

git-svn submodule add --stdlayout svn-project

Where points to a Subversion repository.

I know there is git-svn which allows one to interact with a Subversion repository. So I am thinking, maybe there is a way to checkout a Subversion repository with git-svn and then use it as a submodule.

Best Answer

No. Your best bet would be to set up a mirror of the svn repository in a dedicated git repository.

git svn clone -s mysvnclone
cd mysvnclone
git remote add origin
git push origin master

Then you can add the git repository as a submodule to the original project

cd /path/to/gitproject
git submodule add git:// -- svn-project
git add svn-project
git commit -m "Add submodule"

There is one conceptual difference between svn:externals and git submodule that may trip you up if you approach this from a subversion point of view. The git submodule is pegged to the revision that you give it. If "upstream" changes, then you have to update your submodule's reference.

So when we resync with the upstream subversion:

cd /path/to/mysvnclone
git svn rebase
git push

... the git project will still use the original revision that we committed earlier. To update to the svn HEAD, you would have to use

cd /path/to/gitproject/svn-project
git checkout master
git pull
cd ..
git add svn-project
git commit -m"Update submodule"