Skip to content

Instantly share code, notes, and snippets.

@smdabdoub
Created June 9, 2015 14:02
Show Gist options
  • Save smdabdoub/17065c348289158277b5 to your computer and use it in GitHub Desktop.
Save smdabdoub/17065c348289158277b5 to your computer and use it in GitHub Desktop.
Merge one git repository into another repository as a sub-directory
# based on the following:
# http://saintgimp.org/2013/01/22/merging-two-git-repositories-into-one-repository-without-losing-file-history/
# http://blog.caplin.com/2013/09/18/merging-two-git-repositories/
git clone repo_main
git clone repo_sub
cd repo_main
git remote add repo_sub ../repo_sub
git fetch repo_sub
git checkout -b repo_sub repo_sub/master
mkdir dir_repo_sub
# '*' will cause git mv to fail because it cannot move dir_repo_sub into itself
git mv <list all files>
git commit -m"Moves all repo_sub files into a single directory for merging back into repo_main"
git checkout master
git merge repo_sub
# commit and push, and you're finished
@tonoriesco
Copy link

It's evident but just if you want to change your code:
Line 16:
git mv <list all files>
should be:
git mv <list all files> dir_repo_sub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment