A happy way to combine SVN and Git

Categories: Software Product Development |

Combine SVN And GIT
SVN and Git have different approaches, two different models of version control: the centralized and the distributed. In practice they are quite similar but, in fact, there are big differences between them. So, when it comes to make a choice and pick just one, you will have to consider cautiously their pros and cons. Let’s take a look at them so you can.

Pros and Cons about centralized model

  • Looks simpler.
  • There are a lot of tools which let you work with centralized repositories. Even there is more documentation given that is a classic models with a lot of years in the market.
  • Full support from several IDE.
  • There aren’t offline commits, which is a problem sometimes.
  • You may find some troubles working with local branches.
  • Troubles on the workflow with large teams.

Pros and Cons about distributed model

  •  Easy collaboration model.
  • You can commit offline, which is great.
  • Easier installation and a lot of hosting services available.
  • Complete copy of the repository on each clon.
  • Almost all the work is offline, which is great too.
  • The workflow sometimes is more complex. This worsens when you have many users with different permissions level.
  • Higher learning curve.

Main differences

History handling: To SVN a project never changes, while Git lets you modify previous commits using, for example, git rebase. SVN lets you modify the commit message, but this needs administrator privileges, something that is not recommendable to give to many users.

Directory structure: SVN has different folders per each trunk, branches and tags, while Git uses the same folder for master, branches and tags.

Subprojects: A subproject lets you share code between projects. SVN uses svn-externals and Git uses Git submodels; the concept is the same but the implementation and workflow are different.

You can find more information about these differences in this post from Github: https://help.github.com/articles/what-are-the-differences-between-svn-and-git

The successful combination

There are specific cases when the combination of them solves many problems and makes the workflow really good.

Some of our clients choose SVN to handle their projects and they have a very strong technical explanation to do it. The secret is that we can take advantage of Git and use it for local branches.

This diagram explains the workflow:

Workflow when SVN and GIT are combined

Git-SVN doesn’t handle very well SVN-externals. So, instead of using Git-SVN, a better workflow  is to add two lines to the gitignore and let them work their magic.  This is the main workflow:

  • svn checkout <path_of_SVN_server>
  • git init (on SVN folder)
  • Add .svn/ to .gitignore (main folder of SVN)
  • Add */.svn/ to .gitignore (multiple folders of SVN)
  • Continue working with Git, using local branches and tags.
  • Update and synchronize the Git master before make an SVN commit. The Git master should have all the time an updated version of SVN repository.
  • The Git commits always to go to the Git master and from the Git Master to SVN. This is very helpful to avoid errors.

I hope you’d find this useful! In case you have some question about this technique to combine Git and SVN, leave a comment and I’ll try to help you.