Git – Merge Repositories Without Losing Commit History

git-logoSometimes, you need to merge multiples repos, but you don’t want to loose your commit history. In this tutorial, it’s basically repoSource1 + repoSource2 = repoTarget.




  1. Create source repoSource1, 2 (optionnal)
  2. Check existing history on repoSource1, 2
  3. Merge repoSource1, 2, to repoTarget
  4. Check history on repoTarget

1. Create repos 1, 2 (optionnal)

In GIT command line > create repo : create folder > init git > add commit: create file > add to git > commit.

cd git
mkdir repoSource1
cd repoSource1
git init
copy null > file1.txt
git add *
git commit -m "create file1.txt"
cd git
mkdir repoSource2
cd repoSource2
git init
copy null > file2.txt
git add *
git commit -m "create file2.txt"


2. Check histories on existing repos

In GIT command line > repo 1 > git log > repo 2 > git log.

cd git/repoSource1
git log
cd git/repoSource2
git log


3. Merge repos 1, 2, to repo 3

In GIT command line > create target repo > add remote repo > merge > repeat…

cd git
mkdir repoTarget
cd repoTarget
git init

git remote add repoSource2 ..\repoSource2
git fetch repoSource2
git merge repoSource2/master --allow-unrelated-histories

git log

git remote add repoSource1 ..\repoSource1
git fetch repoSource1
git merge repoSource1/master --allow-unrelated-histories

git log


4. Compare histories between repos

In GIT command line > for each repo: > git log > compare commit hash code and date

cd git\repoTarget
git log

cd ..\repoSource1
git log

cd ..\repoSource2
git log




With this method, commit history and order (by date) is preserved.



Merging Two Git Repositories Into One Repository Without Losing File History

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s