Sunny Milenov Sunny Milenov - 1 year ago 78
Git Question

How to syncronise remote branches with trunk using git-svn

I'm using git-svn to work against svn repository. The layout is standard, and I have created the local repository with:

$ git svn clone -s http://mysvnrepo

I need to work on a remote (svn) branch - MyBranch, so I created a local branch to track the remote one:

(master)$ git checkout -b localMyBranch remotes/MyBranch

I keep workking and committing to the local branch as I go, and occasionally I do dcommit:

(localMyBranch)$ git svn dcommit

Meanwhile other people are working on the trunk, and from time to time I want to merge back the changes from trunk to my branch to keep them in sync. That's where I get really confused, as I could not find a good information how to perform this. So far I know that I need to do:

(localMyBranch)$ git svn dcommit
(localMyBranch)$ git checkout master
(master)$ git svn rebase

Now what? I read that this is NOT the right way to go:

(master)$ git checkout localMyBranch
(localMyBranch)$ git rebase master

As it's going to mess the merge info for svn.

So what is the best way to "rebase" my remote svn branch to the remote trunk, preserving the merge info for svn?

Answer Source

You'll want to create a local working branch to handle your merge. The key is that you need a branch that is not actively tracking a remote svn branch.

Try this:

(localMyBranch)$ git checkout -b merge_work
(merge_work)$ git merge master
(merge_work)$ git checkout localMyBranch
(localMyBranch)$ git rebase merge_work

and vice-versa for merges the other way.


If you are using git-svn 1.7.7 or higher, there is a configuration setting to tell git-svn to populate the mergeinfo property on the remote repository:

git config --global svn.pushmergeinfo true