git svn dcommit on local branch re-creates local master


Our team needs to connect to an svn server and work on a particular branch (not the svn trunk). On top, we need to also get the trunk and merge between them.

  • How to clone svn repo with git svn and be able to commit to both git and svn?
  • What is the origin of the name 'dcommit' in git svn dcommit?
  • git svn dcommit fails with “Incomplete data: Delta source ended unexpectedly”
  • How can I avoid an accidental dcommit from a local branch
  • Git svn fetch, rebase, reset and dcommit functions all hang with no error on one svn branch
  • Using TortoiseGit, can I commit and svn dcommit in one step?
  • I have set up a local git repository connected to our branch (“svn+ssh…project/branches/X”).

    Then, I have manually added the trunk as a new svn connection (“svn+ssh…project/trunk”) (I added a new remote target for the svn trunk, to .git/config) and renamed my branches as follows:

    master (connected to project/branches/X) was renamed to master-X

    the branch connected to project/trunk was renamed to master-trunk.


    When I git svn dcommit on the master-X local branch, a new ‘master’ branch is created, with the same effect as if I did:

    git svn dcommit
    git co master-X -b master

    Can I prevent the master branch from being recreated?

    (every time it is created I delete it manually afterwards).


    My .git/config now looks like this:

    # original/default configuration settings skipped for brevity
    [svn-remote "svn"]
        url = svn+ssh://...project/branches/X
        fetch = :refs/remotes/git-svn
    [svn-remote "svn-trunk"]
        url = svn+ssh://...project/trunk
        fetch = :refs/remotes/git-svn-trunk

    The last three lines were added by me.

  • diff current working copy of a file with another branch's committed copy
  • What is the URL to a heroku git repository?
  • ERROR virtualenvwrapper in GitBash
  • git track, ignore, delete, untrack
  • Large 66GiB legacy CVS repo — it is a good idea to migrate to GIT or Mercurial?
  • Checkout git repo with chef with ssh key
  • One Solution collect form web for “git svn dcommit on local branch re-creates local master”

    This is old Git behaviour, that has been fixed in recent Git releases. Anything more recent than Git 1.7.12 will no longer automatically recreate a master branch. You can run git --version to get the version of Git you’re currently running.

    That’s not much use if the version that comes with your operating system is earlier than 1.7.12 (the latest I have easy access to, between my Debian, RHEL and Cygwin systems, is 1.7.9).

    If you want to, you should be able to make the change yourself, however. Find the copy of git-svn or git-svn.perl on your system (on mine, it’s /usr/lib/git-core/git-svn), then make the following changes:

    • Below Git::SVN::init_vars(), move the post_fetch_checkout(); line to before the closing brace, so that bit of code looks like so:

      eval {
      fatal $@ if $@;
      exit 0;
    • In the post_fetch_checkout subroutine…

      • Add the following line above the line starting my $gs =:

        return if verify_ref('HEAD^0');
      • Delete the line that reads like so:

        return if verify_ref('refs/heads/master^0')
      • Replace the following lines:

        my $valid_head = verify_ref('HEAD^0');
        command_noisy(qw(update-ref refs/heads/master), $gs->refname);
        return if ($valid_head || !verify_ref('HEAD^0'));

        with the following:

        command_noisy(qw(update-ref HEAD), $gs->refname);
        return unless verify_ref('HEAD^0);

    The above changes will apply the patch that changed this behaviour in the Git source code. You can see that for yourself: the relevant commit is v1.7.11.2-250-ge3bd4dd by Marcin Owsiany.

    Git Baby is a git and github fan, let's start git clone.