Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seamless git svn setup

Tags:

I am a power git user and a happy one at that.

Now, I'm forced to use svn and I am not exactly happy to do so. Not so comfortable using git svn yet.

So, here is the setup I'd like and want.

  • I use a git repo, that is git in all ways with many local branches.
  • I create multiple branches in git regularly and merge, let git handle all of it.
  • I want to send selected git branch as an svn branch with everything mirrored.
  • When I delete a local svn mirrored git branch, the svn branch gets deleted too.

The underlining point is that, I want git to do all the hard work of merge and branch and just push to the svn and make it a store.

Sounds like I'm asking for a git-svn tutorial. Except I have gone thro them many times, and yet, I face errors while I do git svn rebase and git svn commit very often and it always seems to talk to trunk alone.

What I want is mirrored svn commands sent and mirrored branches.

like image 349
lprsd Avatar asked Feb 03 '11 07:02

lprsd


People also ask

Can I use git and SVN at the same time?

No interaction between them. Just ignore the . git folder for SVN and the . svn folder for Git and you should be fine.

Which is Better git or SVN?

SVN is better than Git for architecture performance, binary files, and usability. And it may be better for access control and auditability, based on your needs.

How do I clone a Subversion repository?

You can clone from a SVN repo using the git svn clone command. -s = If your SVN repo follows standard naming convention where main source is in “trunk”, branches are created in “branches”. Here we are telling git svn that trunk is the “trunk” directory, maintenance is the “branches” directory etc.


1 Answers

see this question for a introduction to git svn branch and that question for how to delete remote branches - or below for a complete summary of the basics of git svn (including the information from the two questions mentioned).

To give you a more complete tutorial (the complete setup to cover local and remote branches, commiting, merging local branches - see below the horizontal line for just the branch setup), here's how to work easily with a svn repo:

  • Initialize your local git repo with git svn clone <url>, either with paramter -s (stdlayout) or with the parameters --trunk, --tags, --branches to specify the directory of the trunk, tags and branches inside the svn dir.

-s means, the svn repo has a directory layout like this

/trunk
/branches/new_feature
/branches/long_fix
/tags/0.0.9
/tags/0.1.0

If not, you can specify the location of the trunk, branches and tags with the arguments provided above.

When you clone the repo, you will automatically land in a local branch called master, which will automatically track the trunk.

In this, you do your commits just like you would not know you cloned the repo with git svn, except you do not push commits:

  • Use git commit to do commits to your branch
  • Use git branch <branch name> to create local branches
  • Use git merge <branch name> to merge changes from local branches
  • etc.

You do not need to worry about you are in a git svn-repo, until you want to push your changes.

From the setup above, we have the local branch master which is tracking trunk. So after doing commits inside the local master-branch, they can be pushed to the trunk with the following command:

  • git svn dcommit (inside your local branch master)

(Note the d in dcommit).

To test where you commits would go, do

  • git svn dcommit -n

Now comes the interesting part: create branches on your side that are tracked. Really simple reading the question above, I'll just copy and paste the example:

  • git svn branch -n -m "Branch for authentication bug" auth_bug

Note that this example has the -n flag which only does a dry run. Remove that flag to do it for real. The command creates the branch auth_bug on the svn repo in the branches-directory you set up above, and

  • git checkout -b auth_bug auth_bug

creates a local branch auth_bug (first param) and lets it follow the remote branch auth_bug (second param), which is mapped to the dir /branches/auth_bug on the svn repo. The remote branch auth_bug exists, because you created it with the git svn branch-command (and could be any other branch already existing).

Inside this local branch auth_bug, all your commits will be pushed to the svn repo in the branches dir /branches/auth_bug when doing git svn dcommit (test it by appending -n to the command.)

To delete a branch (I've not done it before), it looks like git svn does not handle this for you, so according to another question, you have to to the following directly using the svn command:

  • svn rm $URL/branches/the_branch

This deletes the branch from the remote svn repo, and then you have to remove it from your local git repo, depending on it was a branch (like in the command above) or a tag:

git branch -D -r the_branch
rm -rf .git/svn/the_branch

or

git branch -D -r tags/the_tag
rm -rf .git/svn/tags/the_tag

To update your branch with changes from the upstream svn branch ("pull"), you can rebase your branch on top of the change with:

  • git svn rebase

This fetches new commits in svn, rebases your branch and plays back your local commits (if any).

like image 183
Markus Avatar answered Nov 15 '22 12:11

Markus