The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


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


git-stitch-repo repo1 repo2:dir2 ...


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.


Imagine we have two repositories A and B that we want to stitch into a repository C so that all the files from A are in subdirectory A and all the files from B are in subdirectory B.

Repository A:

           '     ,master
          /    /

Branch master points to A5 and branch topic points to A3.

Repository B: ,topic ,master B3---B5---B7---B8 / / B1---B2---B4---B6

Branch master points to B8 and branch topic points to B5.

The C repository should preserve chronology, commit relationships and branches as much as possible, while giving the impression that the directories A & B did live side-by-side all the time.

Assuming additional timestamps not shown on the above graphs, git-stitch-repo will produce a git-fast-import stream that will create the following history:

                                    ,topic    ,master
                   /         /         /

Note that the current result is slightly buggy, since A5 wasn't on the topic branch in the original graph for A.


Philippe Bruhat (BooK), <>.


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 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.