My git svn workflow
Below are the steps I use when working with Git & SVN. Please note, I am in no way a Git or SVN expert, but these are the steps that seem to work for me.
1) Checkout codebase
This step only needs to be done once, it will pull down a local copy of the entire history allowing for very fast nagivation of revisions and allow work to be down when no connection to a central repository is available.
git svn clone svn://path/to/code/ --stdlayout
2) Create a topic branch to work on
We now want to start work on our first story, so we create a local branch for it. This allows us to keep all changes related to the first story out of the master branch. By keeping the master branch clean we can create as many local branches as we wish from it allowing us to quickly fix a bug in a separate local branch to the story we are working on. I’ll come to this later. The -b option means checkout and create a branch, this is a shortcut to creating the branch then checking it out.
git checkout -b story1
.. implement the first story ..
3) Add all new/deleted/modified files to staging area
With git you can stage just the files that are important, these staged items then make up the contents of your commit.
git add path/to/resource
4) Create a commit
We then create a commit of the staged files in our local branch, note this differs from SVN as a commit is only local.
git commit -m "My commit message"
5) Merge changes from your topic branch into the master branch
Ensure the master branch is up to date
git checkout master git svn rebase
Then merge your topic branch into master
git merge story1
6) Merge conflicts
Merge any conflicts either manually or using mergetool (I’m yet to figure out how to use the mergetool command)
7) Push to SVN
This is the bridge that takes our Git commits and pushes them to SVN. Each Git commit will be mapped to a respective SVN commit.
git svn dcommit
Working with multiple branches
As I mentioned earlier, one of the major advantages of Git over SVN is the ability to have multiple working branches locally, allowing you to switch between them with relative ease. Take for example you are working on a story, it might take you a whole day to get it done. At midday an urgent support request arrives for a bug in the live software. Using SVN I would typically have to checkout the HEAD revision into a separate directory and import it into Eclipse as a new project. With Git it is much simpler, I use the following steps to do the switching.
# Commit all current work to the topic branch
git add path/to/noncommited/work
# Switch to the master branch and make sure it is up to date
git checkout master git svn rebase
# Create a new branch for the bug fix
git checkout -b bugfix
# Fix the bug
# Follow steps 3-7 above
# Carry on working on the story
git checkout story1
Git GUI
You can use the Git GUI tool for most of the steps above, I find it particularly useful for steps 3 & 4.
You can also review the history and changes using gitk, this is useful for code reviews before you push your code into a master repo.
JGit (Eclipse Plugin)
I use the JGit Eclipse Plugin when working in Eclipse, it provides a diff with the previous version which I find invaluable.
Install in Eclipse using the update site: http://www.jgit.org/updates
References
http://blog.tsunanet.net/2007/07/learning-git-svn-in-5min.html
http://stackoverflow.com/questions/190431/is-git-svn-dcommit-after-merging-in-git-dangerous
http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#resolving-a-merge
2 Comments to My git svn workflow
this is pretty much how I work, except I dont bother doing the feature branch – mostly because I dont need to. At the moment. Maybe I will shortly :)
I tend to use GitExtensions on windows. It’s msysgit and a nice-ish UI on it. Makes staging files a lot easier for me, tho I end up using the command line for almost eveything else.
My workflow is:
git init etc – only did this once, took ages.
work work work
git add etc
git commit as needed. repeat more work
git svn rebase
git svn dcommit
I think I dont need the rebase, ‘cos it does that with the dcommit, but hey – habit.
I also have a patch which makes git svn work a LOT quicker (20secs vrs 2 mins) by dynamically loading the svn libs. Makes working with a very remote server (my svn is in denmark) a lot nicer.
:)
@Nic Feature/story branches to allow for quick context switching and is the main reason I use Git. What are the benefits you see with Git besides cheap local branching?
Leave a comment
Search
Subscribe
Recent Posts
Tags
Archives
What I'm Doing...
- Missed my tube stop playing Archipelago, sign of a compelling game. If only it had multiplayer #android 3 hrs ago
- Beautiful website too! RT @aalmiray http://nosqleu.com/ is the place to be if you care about #nosql 1 day ago
- (2008..new Date()[Calendar.YEAR]).each() {} #lovingthegroovy 2 days ago
- More updates...
January 14, 2010