How to start using Git in SVN-based organization
Join the DZone community and get the full member experience.Join For Free
I've been using Git about a year now, immediately after creation my github account. I got really nice impression of using this tool, but still - on my primary job at e-conomic we are using SVN as primary VCS tool.
You are probably aware about all good thing with Git. If you still don't you might check out these great answers on Stackoverflow. In short - Git adds benefits, but it adds complexity as well.
After a bit evaluation I found that those benefits are worth to stop using SVN and switch to Git. But, if you ask your colleagues "Are you ready to go with Git?" you would probably hear "No!". It is clear why, people are getting used to current tools.. infrastructure are build around them. And switching from one VCS to another seemed as destruction of building fundament for many developers.
Fortunately, Git has a killer feature that other DVCS does not have! And this feature will help you to smoothly start with Git even if your company is still using SVN as standard. Yes, I'm talking about git-svn.
Believe me, it is amazing! I always have a little distrust for such kind of integration tool, but so far it works as charm. So, I'll give you a small instructions that will make you possible to get to your office tomorrow and start use Git as your own VCS.
Setup you environment
- Download and install msysgit
Setup local user information, example
git config --global user.name “alexander.beletsky” git config --global user.email “email@example.com”
If you are on Windows and doing only-Windows development, it is recommended to turn off autocrlf
git config core.autocrlf false
Checking out code from SVN repository
Run git clone command (it might take some time, depending on repository and history size)
git svn clone https://mysvnserver/repo
As clone finished, you will see that new folder repo created with the content of your SVN repository. Now, this folder is actually Git repository + you local sources copy. Try to run git log inside the repository and you will see that all your history are there!
Let's do some work
Now, suppose you start to work on some bugfix. By default, git repository contains one branch called master. Good style is do not do direct commits into master at all, just keep it as synchronization point between SVN repository and your local repository. So, to do actual job you to create branch.
git checkout -b bugfix-id-1453
This command will create new branch called bugfix-id-1453 and immediately switch to it. If you haven't noticed how that happened - please welcome to git's high performance world.
You changed some file and ready to commit. In git it's a 2 steps operation. First, you need to put content to stage.. second, you store the content in new commit object.
git add . git commit -m "issue has been fixed"
Commit changes back to SVN
You've fixed a bug and now fixed is placed in bugfix-id-1453. But you should give it back to rest of the world.
Checkout your master branch:
git checkout master
Get the latest changes from SVN:
git svn rebase
Now SVN server and local master branch are identical. We have to merge our fix into master:
git merge bugfix-id-1453
Now master contains previous SVN state + new fix. We have to synchronize local repository and SVN server:
git svn dcommit
Git-svn is perfect tool to start using git without radical changes in organization. It gives everybody change to try it out, how much it really fits your needs. I'm having a big pleasure now of working with Git. I'm not saying it's ideal smooth process, sure I met some difficulties. But for me those difficulties are nothing comparing the benefits I'm getting with it.
Opinions expressed by DZone contributors are their own.