Overview
You can migrate a DreamHost Subversion (SVN) repository to Git with git svn. The migration preserves your full commit history and maps SVN usernames to real Git author identities.
Prerequisites
The following tools are required and are available on DreamHost servers:
- git
- svn
- git svn (bundled with Git)
To confirm git svn is available, run:
[server]$ git svn --versionStep 1 — Log in and locate your SVN repository
- Log in to your server via SSH for the domain the SVN repo was configured on.
-
Navigate to your home directory:
[server]$ cd ~ -
Confirm the svn directory is present:
[server]$ ls ~/svnYou should see your repository listed. For example:
[server]$ ls ~/svn my_projectYour SVN repository path generally follows this format:
/home/username/svn/my_projectThe svn+ssh:// URL you will use in the steps below is constructed from your DreamHost username, the hostname you SSH into, and that path:
svn+ssh://username@example.com/home/username/svn/my_projectReplace username with your DreamHost username, example.com with the domain you SSH into, and my_project with your repository name.
Step 2 — Build an author mapping file
SVN commits record only a username. Git commits require a name and email address. Before cloning, create a mapping file that translates SVN usernames to Git author identities.
-
Run the following command to extract all unique SVN authors and write them to a file:
[server]$ svn log -q svn+ssh://username@example.com/home/username/svn/my_project \ | awk -F '|' '/^r/ {sub(" ","",$2); sub(" $","",$2); print $2" = "$2" <"$2"@example.com>"}' \ | sort -u > ~/authors.txt -
Open ~/authors.txt in a text editor and replace the placeholder names and email addresses with each contributor's real name and email. Each line must follow this format:
svnusername = First Last <email@example.com>Example:
jsmith = Jane Smith <jane.smith@example.com>
The command above extracts only the authors who appear in the commit log. You only need to include those authors in the file.
Step 3 — Clone the SVN repository
Use git svn clone to import the repository into a new local Git repo.
-
Run the clone command from your home directory:
[server]$ git svn clone --no-metadata -A ~/authors.txt --stdlayout \ svn+ssh://username@example.com/home/username/svn/my_project ~/git-migrationReplace the SVN path and ~/git-migration with your repository path and preferred destination directory.
This command:
- Imports all commits with full history
- Maps SVN usernames to Git authors using your authors.txt file (-A)
- Strips git-svn tracking metadata from commit messages (--no-metadata)
- Expects a standard SVN layout with trunk/, branches/, and tags/ directories (--stdlayout)
If your repository does not use the standard trunk/branches/tags layout, see the Non-standard repository layouts section below.
-
Change into the new directory when the clone finishes:
[server]$ cd ~/git-migration -
Run git log to confirm the history imported correctly:
[server]$ git log
Step 4 (Optional) — Convert svn:ignore to .gitignore
If your SVN repository used svn:ignore properties, convert them to a .gitignore file:
[server]$ git svn show-ignore > .gitignore
[server]$ git add .gitignore
[server]$ git commit -m "Convert svn:ignore to .gitignore"Step 5 — Fix branches and tags
git svn imports SVN branches and tags as remote-tracking branches rather than native Git branches and tags. This step converts them to proper Git references and renames trunk to main.
-
Rename the trunk branch to main:
[server]$ git branch -m trunk main -
Convert SVN tag branches to real Git tags. Adjust the ref path to match what git branch -a shows for your repository:
[server]$ git for-each-ref --format='%(refname:short)' refs/remotes/origin/tags \ | sed 's#origin/tags/##' \ | while read t; do git tag "$t" "refs/remotes/origin/tags/$t"; doneRun git tag to confirm the tags were created.
Step 6 — Push to your new Git repository
You can host the new repository on your DreamHost account over SSH. See Set up a Git repository for DreamHost-hosted options.
-
Add your Git remote:
[server]$ git remote add origin git-repository-url -
Push all branches:
[server]$ git push --all origin -
Push all tags:
[server]$ git push --tags origin
Your migration is complete. You can now use standard Git commands to manage the repository.
How do I clean up the SVN repository?
Once you have confirmed the migration is complete, you can remove the SVN repository from your DreamHost account to free up disk space:
[server]$ rm -rf ~/svn/my_projectVerify your Git history and test the new repository thoroughly before removing the SVN repo. This action cannot be undone.
Non-standard repository layouts
If your SVN repository does not follow the standard trunk/branches/tags layout, use the -T, -b, and -t flags to specify the paths manually instead of --stdlayout:
- -T -- path to trunk (default: trunk)
- -b -- path to branches (default: branches)
- -t -- path to tags (default: tags)
For more granular control -- for example, to import only a specific branch -- you can separate the initialization and fetch steps:
[server]$ git svn init svn+ssh://username@example.com/home/username/svn/my_project ~/git-migration
[server]$ cd ~/git-migration
[server]$ git svn fetchSee the git svn documentation for all available options.
FAQs
Does the migration preserve the full commit history?
Yes. git svn clone imports every commit from your SVN repository, including author information, timestamps, and commit messages. Using the --no-metadata flag keeps commit messages clean by removing git-svn tracking references.
What if a commit author is missing from authors.txt?
The clone will fail with an error identifying the missing username. Add the author to ~/authors.txt and re-run the clone command.
Can I migrate only a specific branch instead of the entire repository?
Yes. Use git svn init to initialize the repository, then run git svn fetch with specific branch paths. The git svn documentation covers all available fetch options.
See also
DreamHost links
Third-party links