pieter3d
pieter3d

Reputation: 135

How can I keep my code synced to both a Git and SVN repository?

At work I own a relatively small software tool (~25k lines of java), and I have been using a Git repo to revision it. Now the tool is going to be part of a larger package that is maintained in a totally different environment by other people, which uses SVN. But I still want to maintain the flexibility of my Git repo, so that I am not rigidly tied to the larger package's release schedule.

Is there a way I can keep my local area in sync with both revision control systems in a way that avoids uploading .svn files to git, and .git files to SVN? Ideally I'd want to keep committing the minor edits to Git, and then periodically push to SVN when requested, all from the same directory. Or am I doomed to keep copying files between two directories on my system?

Upvotes: 0

Views: 315

Answers (1)

sleske
sleske

Reputation: 83609

Your best option is probably to use git-svn. This allows you to use git as a frontend for a Subversion repository.

The simplest way to do this would be:

  • create a SVN repository for the software (or use an existing repo)
  • commit the software to SVN once (as a bunch of folders, using svn commit)
  • use git svn clone to fetch the software as a git repository

The disadvantage is that you lose the git history you have created so far.

If you want to keep the git history, things will get a bit more complex (because SVN cannot represent some aspects of git's history, particularly branches). Basically you'd:

  • create an empty SVN repo
  • check it out using git svn clone
  • import your existing git commits into this git repo
  • push them to the SVN repo (git svn dcommit)

The "import your existing git commits" is where things will get tricky (for example, you will have to rebase on top of the initial commit in the git svn repo, then git svn dcommit will rebase again, which will play havoc with merge commits. However, if you can live with e.g. branches not being represented totally faithfully, you should be fine.

Upvotes: 1

Related Questions