Cloning an SVN Repository into Git with all Tags and Branches

by Kirk Madera

Engineers reusable modular solutions to maintain environments and deployment strategies across teams. Works for food.

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)

  1. 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

  1. git svn clone -s http://somesvnrepo.com/somesvnrepo/ --username=user@example.com destinationdirname;

Script to create tags

This will retain tag messages from SVN.

  1. #!/bin/sh
  2. git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags |
  3. while read tag ref;
  4. do
  5.     tag=`echo$tag| sed "s|tags/||g"`;
  6.     comment="$(git log -1 --format=format:%B $ref)";
  7.     git tag -a $tag-m "$comment"$ref;
  8.     git branch -r -d "tags/$tag"
  9. done;

Script to create branches (after running tags script)

  1. #!/bin/sh
  2. git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes |
  3. while read branch ref;
  4. do
  5.     git branch $branch$ref;
  6. done;
  7. git branch -d trunk;

Push to Git Repo

  1. git remote add origin https://somegitrepo.com/somegitrepo;
  2. git push -u origin --all;
  3. git push -u origin --tags;

Cloning an SVN Repository into Git with all Tags and Branches

Cloning an SVN Repository into Git with all Tags and Branches

by Kirk Madera

Engineers reusable modular solutions to maintain environments and deployment strategies across teams. Works for food.

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)

  1. 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

  1. git svn clone -s http://somesvnrepo.com/somesvnrepo/ --username=user@example.com destinationdirname;

Script to create tags

This will retain tag messages from SVN.

  1. #!/bin/sh
  2. git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags |
  3. while read tag ref;
  4. do
  5.     tag=`echo$tag| sed "s|tags/||g"`;
  6.     comment="$(git log -1 --format=format:%B $ref)";
  7.     git tag -a $tag-m "$comment"$ref;
  8.     git branch -r -d "tags/$tag"
  9. done;

Script to create branches (after running tags script)

  1. #!/bin/sh
  2. git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes |
  3. while read branch ref;
  4. do
  5.     git branch $branch$ref;
  6. done;
  7. git branch -d trunk;

Push to Git Repo

  1. git remote add origin https://somegitrepo.com/somegitrepo;
  2. git push -u origin --all;
  3. git push -u origin --tags;