Git & SVN: How to update a git submodule from a closed svn repository

Hi everybody!

Wanted to share a small recipe for Git and SVN. Perhaps it is not the best one, but is the one that I found to work for me. However, if you have any other ideas or suggestions on how to improve or do it in any other way, please leave a comment below.

I use Git as my main revision tool. However I have a project where I use some submodules from codeplex.com and I usually clone the source code directly from the SVN repo at codeplex.

By doing this, I found the following problem:
After cloning and including the submodules in my projects, how can I continue to update them from SVN?

A quick search over the Internet did not give me any guide on how to update a git project that has been cloned from a closed SVN projects. So, after some tests and tries I found the following steps to work out:

  1. Clone your submodule repo to a new folder

  2. Initialize git-svn:

    git svn init SVN_URL

  3. Get the last revision you previously merged:

    git svn fetch -rREVISION

  4. Check all available branches:

    git branch -a

    You should be able to see remotes/git-svn in the list

  5. Checkout to git-svn branch: git checkout git-svn

    By calling this command you will see the following warning:

    You are in ‘detached HEAD’ state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.

    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:

    git checkout -b new_branch_name

    HEAD is now at 42b27f4… Commit Message.

    Do not panic and just continue to step 6

  6. Create a new branch from your current ‘detached HEAD’ state:

    git checkout -b NEW_BRANCH

  7. Update SVN to the latest revision available:

    git svn rebase (to latest update)

  8. Move back to your development branch:

    git checkout DEV_BRANCH

  9. Merge SVN branch into your development branch:

    git merge NEW_BRANCH

  10. Resolve conflicts if any and push back to server

  11. On your main git repo just pull the latest changes from the remote repo and continue to work as usual.

Hope it helps.