The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


git-stitch-repo - Stitch several git repositories into a git fast-import stream


version 0.108


git-stitch-repo [ options ] repo1:dir1 repo2:dir2 ...


    --select < first | last | random >
                 Algorithm for selection the attachment commit

    --help       Print a short online help and exit
    --manual     Print the full manual page and exit
    --version    Print version information and exit


git-stitch-repo will process the output of git fast-export --all --date-order on the git repositories given on the command-line, and create a stream suitable for git fast-import that will create a new repository containing all the commits in a new commit tree that respects the history of all the source repositories.

Typical usage is like this:

    $ ls
    A  B
    $ mkdir RESULT
    $ cd RESULT
    $ git init
    $ git-stitch-repo ../A ../B ../C:X ../R: | git fast-import

The RESULT repository will contain all commits from repositories ../A ../B ../C & ../R, with the paths of the files rewritten: the files from the ../A repository will be in subdirectory A/ of the new repository, the files from ../B in its subdirectory B/, the files from ../C in subdirectory X/, and the files from ../R in its root directory.

    $ git checkout master-A
    warning: You appear to be on a branch yet to be born.
    warning: Forcing checkout of master-A.
    Switched to branch "master-A"
    $ git checkout master-B
    Switched to branch "master-B"

Both branches can be seen using gitk --all. It is now possible to create the master branch and have it point at the right commit, and delete the two master-A and master-B branches.

git-stich-repo works perfectly with repositories that have a linear history (no merges). It has successfully been tested with 16 linear repositories, and produced the expected result.

The improvements to the stitching algorithm added in version 0.06 should make is suitable to work with repositories having branches and merges.




The original version of this script was created as part of my work for BOOKING.COM, which authorized its publication/distribution under the same terms as Perl itself.


Copyright 2008-2019 Philippe Bruhat (BooK), All Rights Reserved.


This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.