Search code examples
gitmergerepository

Git: Merging repositories with related histories into one


Let's say I have two repositories where the first repo's history ends where the second one's begins. Like this:

A -- B   C -- D

How do I merge them so that I have this:

A -- B -- C -- D

Solution

  • The git filter-branch documentation has an example on how to do this:

    To set a commit (which typically is at the tip of another history) to be the parent of the current initial commit, in order to paste the other history behind the current history:

    git filter-branch --parent-filter 'sed "s/^\$/-p <graft-id>/"' HEAD
    

    To create a virtual parent instead of rewriting the entire history, consider using git replace --graft