Wednesday, July 16, 2014

git svn with svn branches

How can you use git svn and branches on Subversion server?

It’s not quite easy yet and if you never use it it’s fear for you.
You can practice it in your local and you need to follow these procedures.

Practice for git svn with branches on local

You want to practice it on your local, don’t you?

Create local svn repository and clone it.


  • Windows
  • TortoiseSVN
  • Git Extensions

You could follow these steps with other OSes.

First of all you may try to clone a svn repository you created in your local.

$ git svn clone /c/Repos/GitPractices/centralsvn . --stdlayout

but you will fail with it.

Initialized empty Git repository in C:/Repos/GitPractices/localgitsvn-a/.git/
E: 'trunk' is not a complete URL  and a separate URL is not specified

In order to evade it, you need to do the following steps

  1. create svn repository

  2. run svnserve

For Windows you need to run commands in bash, e.g. MINGW32 in Git Extensions.

Don’t use this command:

✘ $ svnserve -d -R --root ./

which runs as read only.


$ svnserve -d --root ./


$ svnserve -d -r ./

And leave that console open.

  1. svn clone
$ git svn clone --prefix svn/ -s svn://localhost/ ./


$ git svn clone -s svn://localhost/ ./

then you will be able to clone it to your local.

And when you try to dcommit, you will fail with an auth error:

$ git svn branch branchb -m "Created Branch B"
Copying svn://localhost/trunk at r2 to svn://localhost/branches/branchb...
Authorization failed: Authorization failed at C:\Program Files (x86)\Git/libexec
/git-core\git-svn line 1183

$ git svn dcommit
Committing to svn://localhost/trunk ...

Authorization failed: Authorization failed
W: d24d77abd34ffddfed52dd4f741be8373f8cd839 and refs/remotes/svn/trunk differ, u
sing rebase:
:040000 000000 2e3c39bdb69f2b4e2f339ff28ec1878897693d05 000000000000000000000000
0000000000000000 D      testa
Current branch master is up to date.
ERROR: Not all changes have been committed into SVN, however the committed
ones (if any) seem to be successfully integrated into the working tree.
Please see the above messages for details.

anno-access = write

Because svnserve runs still as read only for an anonymous user.
In order to evade this, you need to add “anon-access = write” into the conf/svnserve.conf file in the SVN repository, e.g.

anno-access = write

Create SVN branch

Prerequisite: you have SVN repository already like explained above.

Unless you create a SVN branch then you will just dcommit to trunk.
Use git svn branch.

$ git svn branch -m "created Branch B" branchb
Copying svn://localhost/trunk at r4 to svn://localhost/branches/branchb...
Found possible branch point: svn://localhost/trunk => svn://localhost/branches/b
ranchb, 4
Found branch parent: (refs/remotes/svn/branchb) 8a0afc7055ddf7b438b22c1bd4aca5a0
Following parent with do_switch
Successfully followed parent
r5 = 6dace9fa756cf8ea2320d968707ebce50c0bc35d (refs/remotes/svn/branchb)

In case that you’ve created a local Git branch already,
you have to also create SVN branch firstly to dcommit.

Check a svn branch out

Let’s say you have a branch, branchsvn in SVN.

git svn fetch
git checkout -b branchsvn

Then you have branchsvn in your local and switch to it.


git checkout -b <branch name>


git branch <branch name>
git checkout <branch name>


  1. Prepare SVN server to practice
    1. Use svnserve
$ svnserve -d -r ./
  1. Make branches synchronized between local Git repository and SVN repository.
    1. Create SVN branch
      Let’s say you want to have branchb synched with SVN repository.
      Create a SVN repository even if you created the git repository in your local.
      You can skip this if SVN repository already has a branch.
$ git svn branch branchb -m "This is a commit message for new branchb."
1. Check the SVN branch out
git svn fetch
git checkout -b branchb

If you have already a git branch in your local to commit to SVN,
run checkout without -b and rebase SVN remote branch.

git svn fetch
git rebase remotes/branchb
git svn dcommit

So you can dcommit as usual.

A shortcut to create synced branches if you don’t have any branch yet.

$ git checkout -b branchb remotes/branchb

How to synchronize between Git branches and SVN ones.

SVN branch exists. SVN branch doesn’t exist.
Git branch exists. A B
Git branch doesn’t exist. C B or C

Assuming you want to synchronize the branch branchb between Git and SVN,
find your alphabet in the table above and follow the corresponding commands below.

  • A (Git + SVN branches exist)

rebase branchb on SVN

$ git svn fetch
$ git rebase remotes/branchb
  • B (Git branch exists or nothing)

svn branch/rebase branchb

$ git svn branch branchb -m "Created Branch B"
$ git rebase remotes/branchb
  • C (SVN branch exists or nothing)

checkout -b

$ git checkout -b branchb remotes/branchb

No comments:

Post a Comment