Cloning an SVN Repository into Git with all Tags and Branches

git-svn is awesome, but I recently realized that it does not automatically create all tags and branches in Git that are present in SVN. It really just pulls the all into remote branches and leaves them there. This is the full process I used to carry all branches and tags over from an SVN repository into a Git repository.

Install Git SVN (Ubuntu)

sudo apt-get install git-svn;

Pull the SVN Repository into Git

If svn repo has standard trunk, branches, and tags, use this command at the root above those directories

git svn clone -s destinationdirname;

Script to create tags

This will retain tag messages from SVN.

git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags |
while read tag ref;
    tag=`echo $tag | sed "s|tags/||g"`;
    comment="$(git log -1 --format=format:%B $ref)";
    git tag -a $tag -m "$comment" $ref;
    git branch -r -d "tags/$tag"

Script to create branches (after running tags script)

git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes |
while read branch ref;
    git branch $branch $ref;
git branch -d trunk;

Push to Git Repo

git remote add origin;
git push -u origin --all;
git push -u origin --tags;