repo1
|--.git
|--.gitignore
|--repo1_files
repo2
|--.git
|--.gitignore
|--repo2_files
We will move content and history of repo1 to lib directory of repo2
repo2
|--.git
|--.gitignore
|-- lib
|--.gitignore
|--repo1_files
|--repo2_files
https://github.com/newren/git-filter-repo
pip3 install git-filter-repo
# or any other method
## Make fresh clone of repo1 and remove remotes
git clone https://github.com/you/your-repo.git /home/user/repo1
cd /home/user/repo1
git remote remove origin
# Move content of the repo1 root directory to subfolder
git filter-repo --to-subdirectory-filter lib
# Add local modified repo1 as remote to target repo2, copy history, and rebase
cd /home/user/repo1
git remote add tmp /home/user/repo1
git fetch tmp
git checkout tmp/master
git checkout -b feature/some-lib
git rebase -i master
git remote remove tmp
git gc
git prune
``