Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@4lun
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4lun/6af04852080792633987 to your computer and use it in GitHub Desktop.
Save 4lun/6af04852080792633987 to your computer and use it in GitHub Desktop.
# USAGE:
# ./svn-to-git.sh http://$svnrepo/ http://$gitrepo/
#
# Credit: http://blog.jessitron.com/2013/08/converting-from-svn-to-git.html
REPO="$1"
echo -e "\nDownloading svn repository and converting to local git repository: '$(basename $REPO)'\nURL: $REPO\n"
git svn clone --stdlayout --prefix=svn/ "$REPO" ${REPO##*/}
cd "$(basename $REPO)"
# Create git branches
git for-each-ref refs/remotes/svn --format="%(refname:short)" | sed 's#svn/##' | grep -v '^tags' | while read aBranch; do git branch $aBranch svn/$aBranch; done
git branch -D trunk
# Create git tags
git for-each-ref refs/remotes/svn/tags --format="%(refname:short)" | sed 's#svn/tags/##' | while read aTag; do git tag $aTag svn/tags/$aTag; done
git remote add origin "$2"
echo -e "\nPushing local git repository '$(basename $REPO)' to new origin\nURL: $2\n"
git push -u --all origin
git push --tags origin
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment