How to migrate from SVN to Git

Migrating from Subversion to Git preserves complete repository history, branches, tags, and author information while transitioning to distributed version control. With over 25 years of software development experience and as the creator of CoreUI, I’ve migrated numerous legacy SVN repositories to Git. Git’s git-svn tool enables bidirectional communication with SVN repositories and full migration with history preservation. This approach ensures seamless transition from centralized to distributed version control with complete audit trail.

Use git svn clone with authors file to migrate SVN repositories to Git preserving history, branches, and tags.

Basic SVN to Git migration:

# Clone SVN repository
git svn clone http://svn.example.com/repo repo-git

# This creates a Git repository with SVN history
cd repo-git

# Add Git remote
git remote add origin https://github.com/user/repo.git

# Push to Git
git push -u origin main

Migration with standard layout:

# For standard SVN layout (trunk, branches, tags)
git svn clone http://svn.example.com/repo \
  --trunk=trunk \
  --branches=branches \
  --tags=tags \
  repo-git

cd repo-git

# Convert SVN tags to Git tags
git for-each-ref refs/remotes/origin/tags | cut -d / -f 5- | \
  while read tag; do
    git tag "$tag" "refs/remotes/origin/tags/$tag"
    git branch -r -d "origin/tags/$tag"
  done

# Convert SVN branches to Git branches
git for-each-ref refs/remotes/origin | cut -d / -f 4- | \
  grep -v "^tags" | \
  while read branch; do
    git branch "$branch" "refs/remotes/origin/$branch"
    git branch -r -d "origin/$branch"
  done

Authors mapping file:

# Create authors.txt file mapping SVN to Git authors
# Format: svnuser = Git User <[email protected]>

cat > authors.txt <<EOF
john = John Doe <[email protected]>
jane = Jane Smith <[email protected]>
bob = Bob Johnson <[email protected]>
EOF

# Clone with authors file
git svn clone http://svn.example.com/repo \
  --authors-file=authors.txt \
  --trunk=trunk \
  --branches=branches \
  --tags=tags \
  repo-git

Generate authors file from SVN:

# Extract all SVN authors
svn log -q http://svn.example.com/repo | \
  awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2}' | \
  sort -u > svn-authors.txt

# Create template for mapping
while read author; do
  echo "$author = $author <$author@example.com>"
done < svn-authors.txt > authors.txt

# Edit authors.txt to add proper names and emails

Incremental migration:

# Initial clone
git svn clone -r 1:1000 http://svn.example.com/repo repo-git

cd repo-git

# Fetch more revisions
git svn fetch -r 1001:2000

# Continue until current
git svn fetch

# Final sync before cutover
git svn rebase

Complete migration script:

#!/bin/bash
# svn-to-git-migration.sh

SVN_REPO="http://svn.example.com/repo"
GIT_REPO="https://github.com/user/repo.git"
AUTHORS_FILE="authors.txt"
TEMP_DIR="temp-migration"

echo "Starting SVN to Git migration..."

# 1. Generate authors file if doesn't exist
if [ ! -f "$AUTHORS_FILE" ]; then
  echo "Generating authors file..."
  svn log -q "$SVN_REPO" | \
    awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2}' | \
    sort -u | \
    while read author; do
      echo "$author = $author <$author@example.com>"
    done > "$AUTHORS_FILE"

  echo "Edit $AUTHORS_FILE with correct names and emails, then re-run"
  exit 1
fi

# 2. Clone SVN repository
echo "Cloning SVN repository..."
git svn clone "$SVN_REPO" \
  --authors-file="$AUTHORS_FILE" \
  --trunk=trunk \
  --branches=branches \
  --tags=tags \
  "$TEMP_DIR"

cd "$TEMP_DIR"

# 3. Convert SVN tags to Git tags
echo "Converting tags..."
git for-each-ref refs/remotes/origin/tags | cut -d / -f 5- | \
  while read tag; do
    git tag "$tag" "refs/remotes/origin/tags/$tag"
    git branch -r -d "origin/tags/$tag"
  done

# 4. Convert SVN branches to Git branches
echo "Converting branches..."
git for-each-ref refs/remotes/origin | cut -d / -f 4- | \
  grep -v "^tags" | grep -v "^trunk" | \
  while read branch; do
    git branch "$branch" "refs/remotes/origin/$branch"
    git branch -r -d "origin/$branch"
  done

# 5. Rename trunk to main
git branch -m trunk main

# 6. Remove Git-SVN metadata
git config --remove-section svn-remote.svn
rm -rf .git/svn

# 7. Add Git remote
git remote add origin "$GIT_REPO"

# 8. Push to Git
echo "Pushing to Git repository..."
git push -u origin main
git push origin --all
git push origin --tags

echo "Migration completed!"
echo "Verify the repository and update team"

Verify migration:

# Check commit count
svn log -q http://svn.example.com/repo | grep "^r" | wc -l
git log --oneline | wc -l

# Compare latest revision
svn info http://svn.example.com/repo | grep "Revision"
git log -1 --format="%H %s"

# Verify branches
svn ls http://svn.example.com/repo/branches
git branch -a

# Verify tags
svn ls http://svn.example.com/repo/tags
git tag -l

Handle large repositories:

# Clone specific revision range first
git svn clone -r 1000:HEAD http://svn.example.com/repo repo-git

# Or shallow clone
git svn clone --shallow http://svn.example.com/repo repo-git

# For very large repos, consider splitting history

Post-migration cleanup:

# Remove SVN ignore properties and convert to .gitignore
git svn show-ignore > .gitignore
git add .gitignore
git commit -m "Add .gitignore from SVN ignore properties"

# Clean up large files if needed
git filter-branch --tree-filter 'rm -rf old-large-dir' HEAD

# Run garbage collection
git gc --aggressive --prune=now

Team transition:

# For team members to switch to Git
# 1. Clone new Git repository
git clone https://github.com/user/repo.git

# 2. Remove old SVN checkout
rm -rf old-svn-checkout

# 3. Configure Git
git config user.name "Your Name"
git config user.email "[email protected]"

# 4. Learn Git workflow
# - git pull instead of svn update
# - git push instead of svn commit
# - Feature branches instead of trunk development

Best Practice Note

Use git-svn for migration preserving full history. Create authors file mapping SVN usernames to Git identities. Convert SVN branches and tags to Git equivalents. Test migration on copy before final cutover. Verify commit counts and history after migration. Remove Git-SVN metadata after successful migration. Update team documentation and workflows for Git. Consider gradual migration with git-svn bridge for transition period. This is how we migrate legacy SVN repositories to Git—complete history preservation, proper author attribution, and branch/tag conversion ensuring seamless transition to distributed version control.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.

Answers by CoreUI Core Team