Search This Blog

2011-08-30

Hard SVN branch switch for Git

I have been working with Git through git-svn bridge in SVN based organization together with Alexander Beletsky. We practice Git to solve lots of SVN issues.
There are several tricky moments with git-svn, for instance, SVN branch switching. If there is not quite big difference between your git repository and svn repo, you can use this advice.
But when I had returned from vacation, I found this approach was not working. I have missed one iteration so my Git repository should jump over huge list of changes. Saying in another words, I need just replace my "master" branch with SVN's latest iteration branch.
This solution helped me:

1. Create new git-svn branch.
git config --add svn-remote.SvnRemoteNewBranch.url https://svn/branches/NewIteration
git config --add svn-remote.SvnRemoteNewBranch.fetch :refs/remotes/SvnRemoteNewBranch
git svn fetch SvnRemoteNewBranch
git checkout -b LocalNewBranch -t SvnRemoteNewBranch
git svn rebase SvnRemoteNewBranch 

With it you will get the latest changes from svn to the "LocalNewBranch".
2. Replace "master" branch with svn's one.
git merge -s ours master
git checkout master
git merge LocalNewBranch  

This is it! Your "master" branch has the latest changes.