Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
# based on 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:
# $:./ new-repo-name http://user@server/repo/
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
git tag "$ref" "refs/heads/tags/$ref";
git branch -D "tags/$ref";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment