1

I'd like to move over a branch from an svn location and use it as the master in the github location. Can anyone tell how to do this?

Tom Aranda
  • 5,919
  • 11
  • 35
  • 51
  • Possible duplicate of [How do I migrate an SVN repository with history to a new Git repository?](https://stackoverflow.com/questions/79165/how-do-i-migrate-an-svn-repository-with-history-to-a-new-git-repository) – tkruse Jan 10 '18 at 12:07

2 Answers2

0

You can follow this process by Tiago Rodrigues (trodrigues)

If you want to clone an svn repository with git-svn but don't want it to push all the existing branches, here's what you should do.

Clone with git-svn using the -T parameter to define your trunk path inside the svnrepo, at the same time instructing it to clone only the trunk:

git svn clone -T trunk http://example.com/PROJECT

If instead of cloning trunk you just want to clone a certain branch, do the same thing but change the path given to -T:

 git svn clone -T branches/somefeature http://example.com/PROJECT

This way, git svn will think that branch is the trunk and generate the following config on your .git/config file:

[svn-remote "svn"]
    url = https://example.com/
    fetch = PROJECT/branches/somefeature:refs/remotes/trunk

If at any point after this you want to checkout additional branches, you first need to add it on your configuration file:

[svn-remote "svn"]
    url = https://example.com/
    fetch = PROJECT/branches/somefeature:refs/remotes/trunk
    branches = PROJECT/branches/{anotherfeature}:refs/remotes/*

The branches config always needs a glob. In this case, we're just specifying just one branch but we could specify more, comma separating them, or all with a *.

After this, issue the following command:

git svn fetch

Sit back. It's gonna take a while, and on large repos it might even fail. Sometimes just hitting CTRL+C and starting over solves it. Some dark magic here.

After this, if you issue a git branch -r you can see your remote branch definitions:

git branch -r

anotherfeature

From there you can define a master branch, and push it to a GitHub repo:

git checkout -b master anotherfeature
git remote add origin https://github.com/user/arepo.git
git push -u origin master
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

If you insist on using git-svn, VonC already provided a good answer.

But for a one-time migration git-svn is not the right tool for conversions of repositories or parts of repositories. It is a great tool if you want to use Git as frontend for an existing SVN server, but for one-time conversions you should not use git-svn, but svn2git which is much more suited for this use-case.

There are plenty tools called svn2git, the probably best one is the KDE one from https://github.com/svn-all-fast-export/svn2git. I strongly recommend using that svn2git tool. It is the best I know available out there and it is very flexible in what you can do with its rules files.

You will be easily able to configure svn2gits rule file to produce the result you want from your current SVN layout, including any complex histories like yours that might exist and including producing several Git repos out of one SVN repo or combining different SVN repos into one Git repo cleanly in one run if you like.

If you are not 100% about the history of your repository, svneverever from http://blog.hartwork.org/?p=763 is a great tool to investigate the history of an SVN repository when migrating it to Git.


Even though git-svn or the nirvdrum svn2git is easier to start with, here are some further reasons why using the KDE svn2git instead of git-svn is superior, besides its flexibility:

  • the history is rebuilt much better and cleaner by svn2git (if the correct one is used), this is especially the case for more complex histories with branches and merges and so on
  • the tags are real tags and not branches in Git
  • with git-svn the tags contain an extra empty commit which also makes them not part of the branches, so a normal fetch will not get them until you give --tags to the command as by default only tags pointing to fetched branches are fetched also. With the proper svn2git tags are where they belong
  • if you changed layout in SVN you can easily configure this with svn2git, with git-svn you will loose history eventually
  • with svn2git you can also split one SVN repository into multiple Git repositories easily
  • or combine multiple SVN repositories in the same SVN root into one Git repository easily
  • the conversion is a gazillion times faster with the correct svn2git than with git-svn

You see, there are many reasons why git-svn is worse and the KDE svn2git is superior. :-)

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • Actually... the best tool for a one-shot migration is SubGit: https://subgit.com/ (free for one-shot migration) – VonC Jan 10 '18 at 10:18
  • Not really. It is way too inflexible compared to what you can do with the `svn2git` rules to be called better. – Vampire Jan 10 '18 at 15:43