When converting from svn to git using git-svn or svn2git, how can I change the base path of the repository and possibly still keep branches/tags?

I’m moving a project from SVN to git (completely, so no need for git svn‘s SVN interop features) and I’ve tried using both git svn and svn2git (nirvdrum’s fork on github) and one problem I’ve got is that our repository layout in SVN was like so:


  • Using Dropbox to synchronize files and having them backed up in version control
  • Multiple git pull in one folder containing multiple repository
  • git: Simple solution for pushing between working copies
  • Error publishing master branch to GitHub from VS.NET
  • got a git merge issue after git pull
  • IntelliJ annotate vs git blame
  • and so when I import it into git, the root directory of the repository contains one directory, base (not the real name) and then all the stuff. This is kind of a problem for us, as it adds a few complications.

    Is there a good and easy way to change the root of the repository to be base, either during the import or retroactively with git’s mad history-changing powers? Otherwise, a directory that shouldn’t be the root of the repository and contains other unrelated code will have to be the root of the repository in git, which is strange, and for some reason, with SVN this was not the case (i.e. the root of the repository was base, and the parent directory did not have any svn stuff).

    Hopefully this is a quick question that someone can answer easily.

    Oh, by the way, I do sort of have branches and tags I want to import, but again these should be rooted at base, not the parent directory of base. It’s not a biggie if these aren’t possible to be imported like that because they are pretty much useless and the team was kind of half-heartedly using SVN before, but it would be nice to have them.

  • Adding git branch on the Bash command prompt
  • How to manage one only key per each git repository?
  • How to set GIT_DIR & GIT_WORK_TREE when maintaining multiple repositories
  • git: rewrite history: reorder and merge commits
  • Pass arguments to svn when using CruiseControl.net
  • Git overwrites files during a merge - does not show conflicts
  • 2 Solutions collect form web for “When converting from svn to git using git-svn or svn2git, how can I change the base path of the repository and possibly still keep branches/tags?”

    svn2git takes options for that as well; using the example in Charles’ answer it would be:

    svn2git --trunk example.com/website/trunk/base/code \
            --tags example.com/website/tags/base/code \
            --branches example.com/website/branches/base/code

    [Caveat: I haven’t tried this, but as far as I know, svn2git just converts those into the -T|t|b options for git-svn.]

    You should be able to do:

    git svn init -Texample.com/website/trunk/base/code -texample.com/website/tags/base/code -bexample.com/website/branches/base/code

    instead of accepting the default or using -s|--stdlayout.

    Git Baby is a git and github fan, let's start git clone.