merge unrelated git history

This is useful for incorporating third-party code into your project, as an alternative to git submodule

TL;DR

e.g. you want to incorporate their_project (master) into your_project/libs/their_project (master)

# modify target repo to put all files into a subdirectory,
# i.e. libs/their_project
cd <their project>
git filter-repo --to-subdirectory-filter libs/their_project

# add target project to yoru remote
cd <your_project>
git remote add <rname_theirs> <url-to-their-project>

# do the merging
git merge --allow-unrelated-histories <rname_thries>/master

# remove temporaroy remote
git remote remove <rname_theirs>

Effect

git history of your_project before the merge

* a0c3793 (HEAD -> master) add makefile
* 8100bab add readme
* 2451af5 add hello world

git history of their_project

* af8683a (HEAD -> master) lib: fix abc
* e232dc4 modify readme
* a0e5690 lib: add xyz

the resulting git hostiry of your_project

*   8b19fed (HEAD -> master) Merge remote-tracking branch 'libxyz/master'
|\  
| * af8683a (libxyz/master) lib: fix abc
| * e232dc4 modify readme
| * a0e5690 lib: add xyz
* a0c3793 add makefile
* 8100bab add readme
* 2451af5 add hello world

see @a0e5690, the two branches have no common ancestor

ref

Merge two Git repositories without breaking file history https://stackoverflow.com/questions/13040958