minghua
minghua

Reputation: 6583

How to do a bidirectional synchronization between GIT and SVN

How can you do a bidirectional synchronization between a GIT repository and a SVN repository? I've seen how you can convert from SVN to GIT, but not much about how you can synchronize smoothly between the two.

The purpose is to save the project in both types of repositories and have them producing/tracking identical content.

As an extra requirement, the SVN repository as the subject does not contain trunk and branches.

Upvotes: 2

Views: 2399

Answers (2)

minghua
minghua

Reputation: 6583

This post - Creating a two way sync between a Github repository and Subversion - looks to be a solution:

  • Create a git repo on a github server or a bitbucket server. Clone the empty repo. Add a readme-git file and commit on master.

  • Initially create the svn tracking branch:

    git branch --no-track svnsync
    git checkout svnsync
    git svn init http://your-svn-server/your-repo
                # here removed  `-s`  if the svn repo is not on a standard layout
                # or use file:///path/to/local/repo
    git svn fetch
                # add if needed  `--authors-file svn-authors.txt`
    git reset --hard remotes/git-svn
                # the post said `remotes/trunk` but it does not look right
  • Sync from svn to git:
    git checkout svnsync
    git svn rebase
    git checkout master
    git merge svnsync
                # add  `--allow-unrelated-histories`  to the first merge
    git push origin master
  • Sync from git to svn:
    git checkout master
    git pull origin master
    git checkout svnsync
    git svn rebase
    git merge --no-ff master
    git commit
    git svn dcommit

A drawback of the above sequence is that a bogus readme-git file was added so that a non-tracking branch could be pulled. Starting with a git repo that is initially cloned from the svn repo may avoid the problem, I guess.

Upvotes: 4

VonC
VonC

Reputation: 1324278

You would need a dedicated third-party tool in order to ensure true bi-directional synchronisation between an SNV and Git repositories.

I only know of SubGit to be able to do that reliably. But it is not free. Only the one-shot migration from SVN to Git is.

Upvotes: 3

Related Questions