Question

I'm currently in the process of migrating my team from SVN to GIT.

Rather than clone the whole entire subversion repo, I opted for...

git svn clone http://foo.com/svn/branches/dev --no-minimize-url --authors-file=users.txt foo

This currectly pulls down the dev branch for me.

Then I added a git repo with

git remote add origin git@github.com:foo/bar.git

So, the issue I am having is keeping the GitHub repo up to date w/ what's in SVN.

I had to make some changes to .gitattributes (which may require another question), because I'm running the import process on OSX and since most of the code is written in Windows I kept running into line ending issues.

What I've been doing to update GitHub is...

git svn fetch
git svn rebase

For whatever reason, every time that I do this, I end up having to do a git push --force because my remote/origin/master is diverged off.

So, should I not be rebasing and simply be fetching and have an actual local git-svn branch and merging that into master? Or is there something else I'm missing?

Was it helpful?

Solution

It's not clear to me whether your intention is to have the GitHub repo merely be an exact mirror of the SVN repo, or if you are also doing additional work within your local git repo that you are trying to push to both repos.

If the intention is merely to mirror the repo, your flow should work fine. Running:

git svn fetch
git svn rebase

Should first pull down the new SVN commits into your remote tracking branch (i.e. refs/remotes/trunk) and then merely do a fast-forward of the local master reference to that commit. Then you should be able to push these new commits to GitHub with no issues.

If you are, however, making local changes to the repo, then git svn rebase will basically be rewriting those local commits. If you pushed those local commits to GitHub already, the new ones are effectively a new branch which would cause you to diverge and require a force push.

Another thing to note... if you are making local commits, then committing back to SVN via git svn dcommit note that your local commits are actually rewritten, even if the SVN repo has not diverged in the meantime. The git-svn tool rewrites your commits to include a unique identifier it uses to associate commits in the two repos. This can cause problems when you are dealing with both an SVN remote and a git remote depending on what order you are pushing in. If you push commits to GitHub first, then SVN second, that can also cause you to diverge. From the git-scm book:

This takes all the commits you’ve made on top of the Subversion server code, does a Subversion commit for each, and then rewrites your local Git commit to include a unique identifier. This is important because it means that all the SHA-1 checksums for your commits change. Partly for this reason, working with Git-based remote versions of your projects concurrently with a Subversion server isn’t a good idea.

The upshot of all this is, if you are doing this purely for mirroring, or if you are very careful with the flow, you can get away with having concurrent SVN and git remotes. Otherwise, things are going to be a constant headache.

If I'm misunderstood any part of your question, let me know. HTH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top