Skip to content

Instantly share code, notes, and snippets.

@geraintp
Last active August 29, 2015 14:02
Show Gist options
  • Save geraintp/89f96d8ca6ec2beabe4a to your computer and use it in GitHub Desktop.
Save geraintp/89f96d8ca6ec2beabe4a to your computer and use it in GitHub Desktop.
Shell script to automatically (ish) convert a SVN repo to a a bare GIT repo
#!/bin/sh
# based on http://john.albin.net/git/convert-subversion-to-git with a some tweeks
# (NB: its quick and dirty, has no error checking and only works on repos structured with a stdlayout i.e. a trunk folder)
# use:
#
# $:./svn-to-git.sh new-repo-name http://user@server/repo/
BARE_REPO_NAME="$1"
SVN_PATH="$2"
cd ~/
# Create a Bare Repository
git init --bare ~/$BARE_REPO_NAME.git
cd ~/$BARE_REPO_NAME.git
git symbolic-ref HEAD refs/heads/trunk
# Clone the Subversion repository using git-svn
cd ~/
git svn clone $SVN_PATH --no-metadata -A authors-transform.txt --stdlayout ~/temp
# Convert svn:ignore properties to .gitignore
cd ~/temp
git svn show-ignore > .gitignore
git add .gitignore
git commit -m 'Convert svn:ignore properties to .gitignore.'
# Push repository to a bare git repository
git remote add bare ~/$BARE_REPO_NAME.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare
# Rename “trunk” branch to “master”
cd ~/$BARE_REPO_NAME.git
git branch -m trunk master
rm -rf ~/temp
# Clean up branches and tags
git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
do
git tag "$ref" "refs/heads/tags/$ref";
git branch -D "tags/$ref";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment