git-svn branch

Dear Lazyweb,

how do I push a local git branch to a new svn branch? The other way round is quite easy and well documented but I didn’t find a single document describing what I want to do.

I’m working with an svn repository with standard layout. I use git-svn to be able to use git locally. Until now I’ve always had my master branch reflect the svn’s trunk. For every new feature, I created a local git branch, merged with the master branch when I was done and dcommit’ed it to the svn’s trunk. But now I need to publish an experimental feature which should not yet go into the trunk so I have to publish my local git branch to an svn branch.

I tried git-svn branch foo in the local git branch and it created a svn branch/foo for me but not from the current git branch but from the current master (remote/trunk). That’s of course not what I wanted, I wanted to push the current branch where I’m in and have it linked to the remote svn branch.

Neither the manpage of git-svn nor some documentation in the web helped me. I even found a pretty detailed document which describes each and every aspect of git-svn but unfortunately not mine.

Is this use case so unusual that no one else uses git-svn this way or is it my weak git-FU?

7 thoughts on “git-svn branch

  1. Björn Steinbrink

    git-svn supports that only since 1.6.1, which introduced new “git svn branch” and “git svn tag” commands. I have two ugly shell hacks to do that with older git versions, but seriously, just upgrading git if you’re on an older version is a better idea.

  2. Björn Steinbrink

    Argh, brainfart, I somehow completely missed the third paragraph :-(

    The “git svn branch” part is really just the branch creation (like “svn cp trunk branch”). After that, you should have a new remote tracking branch (see “git branch -r”) and can rebase your stuff onto it, like:
    git rebase –onto $new_svn_branch master $git_branch

    What that does is that it turns the commits in the range master..$git_branch into patches, applies them on top of $new_svn_branch and then updates $git_branch to reference the result.

    And then “git svn dcommit -n” should tell you that it’s going to dcommit your stuff to the new svn branch.

  3. Cameron

    I had to do this recently, and only having git 1.5 I couldn’t use “git svn branch”. If it’s not working for you (or for anyone else stuck on 1.5), then try what I did: use the old “svn cp” to create a new branch (which is easy since you don’t need to check anything out to do it). Then “git svn fetch” to retrieve the new branch and “git checkout -b remotes/”. Then you can do as Bjorn describes and rebase your local git branch’s commits onto the new branch and dcommit them. Good luck!

  4. Cameron

    Sorry, some of my variables got removed due to the angle brackets I used. The checkout command should be “git checkout -b new_branch remotes/new_svn_branch”, but you probably new that. :)

  5. Kimb

    1. checkout the commit in the main branch you started your git-branched work from
    2. git svn branch svn-branch-name
    3. checkout your git branch
    4. rebase onto svn-branch-name
    5. dcommit

  6. Pingback: Creating a new Subversion branch from an existing local Git branch « Barking Iguana

Comments are closed.