Skip to content

Instantly share code, notes, and snippets.

@0xBigBoss
Created January 17, 2023 04:56
Show Gist options
  • Save 0xBigBoss/e6f5e7b8f1059a639d8d425efcd63f6a to your computer and use it in GitHub Desktop.
Save 0xBigBoss/e6f5e7b8f1059a639d8d425efcd63f6a to your computer and use it in GitHub Desktop.
How to merge two separate repos, combine git histories, and nesting one inside a directory.
https://stackoverflow.com/a/10548919/20335188
# steps to merge child-repo into parent-repo
brew install git-filter-repo # will need it later
git clone https://github.com/yourusername/child-repo.git
cd child-repo
git filter-repo --to-subdirectory-filter child-repo # rewrite history to move all files to child-repo folder
cd ..
# now we have a repo with all files in child-repo folder for git history
# we need to merge it with the parent-repo
git clone https://github.com/yourusername/parent-repo.git
cd parent-repo
# create a new branch to merge child-repo into
git switch -c merge-child-repo
# add child-repo as a new folder
git remote add child-repo ../child-repo
git fetch child-repo --tags
# merge master branch of child-repo into parent-repo
git merge --no-ff --allow-unrelated-histories child-repo/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment