Sometimes, 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.
- Create source repoSource1, 2 (optionnal)
- Check existing history on repoSource1, 2
- Merge repoSource1, 2, to repoTarget
- Check history on repoTarget
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"
In GIT command line > repo 1 > git log > repo 2 > git log.
cd git/repoSource1
git log
cd git/repoSource2
git log
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
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.
https://github.com/DamienFremont/blog/tree/master/20170614-git-merge-repositories-without-losing-commit-history https://github.com/DamienFremont/blog/tree/master/20170614-git-merge-repositories-without-losing-commit-history
Merging Two Git Repositories Into One Repository Without Losing File History Merging Two Git Repositories Into One Repository Without Losing File History
http://stackoverflow.com/questions/26502970/merge-multiple-git-repositories-into-one-keeping-branches-history http://stackoverflow.com/questions/26502970/merge-multiple-git-repositories-into-one-keeping-branches-history
https://damienfremont.com/2017/06/14/git-merge-repositories-without-losing-commit-history/