Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosspohr/fdda947e01a3ede54af0427664e0dfc4 to your computer and use it in GitHub Desktop.
Save carlosspohr/fdda947e01a3ede54af0427664e0dfc4 to your computer and use it in GitHub Desktop.
Merge one git repository into another repository as a sub-directory
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
for FILE in `ls -a --ignore dir_repo_sub --ignore .settings --ignore .project --ignore .git`; do git mv $FILE dir_repo_sub/$FILE ; done
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
#fix tags
git tag -l | while read t; do n="dir_repo_sub/${t##*-}"; git tag $n $t; git tag -d $t; done
git push -u origin --tags
git branch -D repo_sub
git push -u origin --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment