git-svn workflow
April 5th, 2011
In this article, we will discuss the workflow for using git-svn. We will use a local merge branch named ‘local-staging’ as the branch into which we will merge our feature branches and from which to dcommit to the remote svn repository. The ‘master’ branch will always track the remote svn repository. This is just a description of what works for me, but should not be considered best-practice.
1) Clone the svn repository
git svn clone -s https://server/svn/product/
2) Create a local-staging branch. The master branch will always track the svn repository, therefore we do not merge anything into the local master. The local-staging branch is used as the trunk into which all feature branches are merged into, before dcommitting to the remote svn repository master.
git checkout master git branch local-staging git checkout local-staging
3) Let’s say we want to create feature branch. We update the local-staging branch and create a local feature branch
git checkout local-staging git svn rebase #update from remote svn git branch my-feature git checkout my-feature
4) Let’s say that a co-developer has updated the remote svn repository and we need to update our local feature-branch. We use the rebase command and it will roll-back your code changes, then download the latest changes from the remote repository, then roll-forward the code by re-applying your code changes.
git checkout my-feature git svn rebase
5) Let’s say we write code within the local feature branch and we wish to commit to the local feature branch. We then create a commit on the local feature branch:
git checkout my-feature hack hack hack git add . git commit -m "my commit message"
6) When the local feature branch is complete, merge it into the local-staging branch. Then create a commit and then push to the remote svn repository master. Be sure to use the—squash to squash all the commits of the local feature branch into a single commit
git checkout local-staging git svn rebase git merge --squash -m "merge message" my-feature git commit -m "my commit message" git svn dcommit git -d my-feature #highly suggested
NOTE: we delete the my-feature branch since it has been squashed and merged into local-staging and dcommitted to the remote svn repository.
If you don’t delete my-feature, then REMEMBER: A local feature branch that has been squashed into the local merge branch and dcommitted, must be considered frozen! If you need to update/change a local feature-branch that has been merged/squashed, DON’T; instead create a new local feature-branch from the local-staging branch.
7) Update the local master branch with the latest changes from the remote svn repository
git checkout master git svn rebase
When you have completed steps 6 and 7 and you are ready to create a new feature branch, proceed back to step 3.
Leave a Reply