Merge git repositories

We have more than 20 Git repositories for the same project, but it causes lots of headaches for building. We’ve decided to merge most of them into a single one, keeping the file history when possible.

This script uses newren/git-filter-repo and as such needs Python 3.

It’s done in 3 steps:

  • clone the local repositories from d:\dev\xxx to d:\devnew\xxx using git-filter-repo with source and target parameters
  • create a new repository at d:\devnew\merged
  • merge from d:\devnew\xxx to d:\devnew\merged\xxx using git merge --allow-unrelated-histories

I’ve removed a lot of code for brievity, so maybe it won’t work out of the box, but you should get the general idea.

Next up: pushing the new repository, then migrate the developers workstations, for which I wrote another script:

Next up: migrating Jenkins jobs. With more than 170 jobs, doing it by hand is a real chore. Fortunately, you can also automate it.

Now we can version the Jenkins configs. Then we edit, and update them.

Git-svn and branches

I’m using git-svn to leverage the power of git while the rest of the company prefers the simplicity of svn.

I have created a local branch, intending to merge it in the trunk/master when I’m done, but it turns out it’s much more complicated than expected. So, I want to commit it on svn.
I already have checked out the full repository.

The most simple solution I have found; all other solutions fiddle with the git config files, and I don’t like it:

  • Checkout the branch: git checkout mybranch
  • Rename the local branch: git branch -m mybranch-temp
  • Create a remote branch “mybranch” in SVN using Tortoise SVN
  • Fetch the SVN repository to get the new branch: git svn fetch
  • Check that the new SVN branch has been fetched: git branch -r (or git branch -avv )
  • Get back to the master branch: git checkout master
  • Checkout the remote branch: git checkout -b mybranch-svn origin/mybranch
  • Rebase my local branch into the local svn branch: git rebase mybranch-temp
  • Commit the branch in svn: git svn dcommit ; use --dry-run  to check the branch it will commit to, because sometimes it still commits to the trunk (I haven’t found out why).

Use git with your SVN repository

You are just a few simple commands away to start using all the local power of git (local commit and rewind, stash…) over an existing SVN repository.

I say local power, because obviously, SVN being not as powerful as git, you’re still limited in what you can do without breaking everything when you try to commit.

A simple and effective guide can be found here : http://svnrating.com/svn-to-git-migration/

Note that on large SVN repository, the first checkout/clone can take hours, or even days. On our 2400-commits-large, several-Gb repository, the first clone has taken a few days, but it was making my (bi-Xeon + 16Gb RAM…) computer hang a few seconds or minutes every 15 minutes or so. Maybe you’ll have better luck.

But once it’s done… it’s really awesome.