Blog Archives

A two way sync between Git and SVN

  • Create a GIT repository on GitHub.com.
  • Create a local repository from the GitHub repository

Use your SSH-Key (uploaded to GitHub.com)!

$ git clone git@github.com:witchi/PHP-SQL-Parser.git

  • switch to the new repository directory
  • Create a SVN tracking branch, which contains all the SVN changes


$ cd PHP-SQL-Parser
$ git branch --no-track svnsync
$ git checkout svnsync
$ git svn init -s https://php-sql-parser.googlecode.com/svn

  • write a file which contains all SVN authors and store it as svn-authors.txt into the Git repository directory
  • fetch all revisions from SVN
  • set the HEAD of the svnsync GIT branch to the latest SVN revision


phosco@gmx.de = André Rothe <phosco@gmx.de>
greenlion = Justin Swanhart <greenlion@gmail.com>
greenlion@gmail.com = Justin Swanhart <greenlion@gmail.com>
Justin Swanhart = Justin Swanhart <greenlion@gmail.com>
(no author) = Justin Swanhart <greenlion@gmail.com>


$ git svn fetch -A svn-authors.txt
$ git reset --hard remotes/trunk

Merge changes from SVN into Git

  • go to the svnsync branch
  • get all the new revisions from the SVN repository
  • go to the master branch (Git)
  • merge all changes from svnsync into the master
  • use meld to solve merge conflicts
  • upload all changes to the GitHub repository


$ git checkout svnsync
$ git svn rebase -A svn-authors.txt
$ git checkout master
$ git merge svnsync
$ git mergetool
$ git push origin master

Merge changes from Git into SVN

  • go to the master branch of Git
  • get all changes from the Github repository
  • go to the svnsync branch
  • get all new revisions from the SVN
  • merge all Git changes from master into the svnsync branch (without fast-forward, it creates a new commit point)
  • use meld to solve merge conflicts
  • commit the changes into svnsync branch (local)
  • commit the changes to the SVN repository server (remote)


$ git checkout master
$ git pull origin master
$ git checkout svnsync
$ git svn rebase -A svn-authors.txt
$ git merge --no-ff master
$ git mergetool
$ git commit
$ git svn dcommit

First steps with Git

To set some important configuration properties for Git use the following commands:


$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
$ git config --global merge.tool meld

The properties are set for all repositories on the current machine.