Skip to content

Instantly share code, notes, and snippets.

@ticean
Created January 3, 2012 21:14
Show Gist options
  • Save ticean/1556967 to your computer and use it in GitHub Desktop.
Save ticean/1556967 to your computer and use it in GitHub Desktop.
SVN Git Mirror
Bridging SVN & Git
====================
This guide will demonstrate how to mirror SVN commits over to GIT.
Work in progress...
References
-----------
First off, I'll give some credits. I've lifed all this information from various placed on the web.
* http://help.github.com/mac-set-up-git
* http://swik.net/Rails/Robby+on+Rails/git-svn+is+a+gateway+drug/cboew
Procedure
----------
```sh
# Clone an SVN repo with Git
git svn init -s http://svn.yourdomain.com/repos/project_name
cd project_name
# Fetch the SVN branches to the local Git repo
git svn fetch
# Once this is done, you’re local 'master' branch is linked to trunk/.
# Make a new branch for develop & check it out
git checkout -b develop
# Back to master.
git checkout master
# We'll change this to link local 'develop' branch to trunk
git reset --hard production
```
@tannerwatson
Copy link

Where did you get the "production" branch from under the "Creating the Local Git Repository" section?

@chrisdembia
Copy link

Grammar: "you’re" should be "your".

@Kakadu
Copy link

Kakadu commented Jul 1, 2013

I think that git reset --hard production should be read as git reset --hard develop

@k-stailey
Copy link

s/get svn rebase/git svn rebase/

@rcourtna
Copy link

I'm trying to do something similar, but I can't for the life of me understand what this step is doing:

# We'll change this to link local 'develop' branch to trunk
git reset --hard production

Why the reset?

@JuergenKosel
Copy link

Hello,

please take a look at my 14 lines script: https://github.com/JuergenKosel/git-svn-mirror/blob/master/git-svn-mirror.sh.
The script mirrors all branches from svn into a git repository.

@andry81
Copy link

andry81 commented Jul 28, 2018

Here is another one click solution over pure and raw windows batch scripts (windows only).

http://svn.code.sf.net/p/contools/deploy/trunk/solutions/all-in-one/
(no sources inside, you have to checkout it through the svn)

Supported only svn-to-git mirroring.

If you want to something clean and bigger, then you have to write your own one.

UPDATE:
Link does not exist anymore. Have found another solution with permanent migration using subgit + vcstool (with sparse checkout fork):

https://subgit.com/documentation/import-book.html
dirk-thomas/vcstool#243
dirk-thomas/vcstool#249
chronoxor/gil#6
gitextensions/gitextensions#10644
https://git-scm.com/docs/git-sparse-checkout

@farOverNinethousand
Copy link

@andry81
Your link is offline :(

@andry81
Copy link

andry81 commented Oct 29, 2023

@farOverNinethousand I've removed it because completely moved to the git. If you still want to mirror (not migrate, but not excluding that), then I recommend to use the SubGit: https://subgit.com/documentation/

The SubGit is the only reliable solution I could find and it is free for SVN migration:

If you are doing a one-time migration from SVN to git, you may use SubGit without any license — just download the tool.
Yet if you need support, sign up for a trial license.

If you want to start partial migration to migrate later completely, then you can use original repo of vcstool: https://github.com/dirk-thomas/vcstool (vcstool2 has removed support of not Git repositories)

It can use GIT external repositories together with SVN external repositories.

PS: SVN-to-Git mirroring is a pain in arse, DO NOT use it, instead migrate to Git and use Git instead.

@farOverNinethousand
Copy link

@andry81
Damn SVN-to-GIT mirroring is exactly what I wanted to do here.
Many thanks for the super detailed response!

@andry81
Copy link

andry81 commented Nov 1, 2023

@farOverNinethousand There is too many blocks and pitfalls on the road of a full SVN-to-Git mirroring. One of these are svn:externals. There is no a reliable way to mirror them because it requires a remote repo creation on a Git hub or server. There is no such functionality in the Git, because it is a part of a hub. All you can do is write down a script to map all svn:externals to Git branches or external repos, but that is not easy either. I can recall only one script that has tried to acquire this:
https://support.tmatesoft.com/t/script-for-conversion-of-svn-externals-to-git-submodules/2980
https://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/convert-svnexternals

And there won't be any duplex mode. If you commit and pushed something to the Git manually, then you have to manually port it back to the SVN.

@farOverNinethousand
Copy link

@andry81
Okay someone just did exactly what I was looking for (a mirror of the JDownloader SVN repo): mirror/jdownloader#58 (comment)
-> https://github.com/mycodedoesnotcompile2/jdownloader_mirror/
Looks like he did this with github actions?
Thank you nevertheless for your detailed answer. If I ever need to set this up myself, I know where to find all relevant information.

@andry81
Copy link

andry81 commented Nov 1, 2023

@farOverNinethousand

Okay someone just did exactly what I was looking for (a mirror of the JDownloader SVN repo): mirror/jdownloader#58 (comment) -> https://github.com/mycodedoesnotcompile2/jdownloader_mirror/

This is not a complete and automatic mirror. He just checkouts 4 predefined root directories and pushes them into the git repo. If there would be other root directories or a root directory rename, then the script will miss that. All svn properties seems does ignore too.

@farOverNinethousand
Copy link

@andry81
Okay good to know.
The links to the forks are not helpful though as there is no current git mirror of the JDownloader SVN available apart from [maybe] the new one I linked.
Thanks for the additional explanation regarding the missing SVN properties.

@rinrab
Copy link

rinrab commented Mar 18, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment