Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jasongallant/dceb1ce6b2743e7488d1136303f6f4eb to your computer and use it in GitHub Desktop.
Save jasongallant/dceb1ce6b2743e7488d1136303f6f4eb to your computer and use it in GitHub Desktop.
Import existing Git repository into another

Import existing Git repository into another

Folder structure before (2 separate repositories):

XXX
 |- .git
 |- (project files)
YYY
 |- .git
 |- (project files)

Folder structure after:

YYY
 |- .git  <-- This now contains the change history from XXX
 |-  ZZZ  <-- This was originally XXX
      |- (project files)
 |-  (project files)

In YYY:

git remote add XXX_remote <path-or-url-to-XXX-repo>
git fetch XXX_remote
git merge -s ours --no-commit XXX_remote/master
git read-tree --prefix=ZZZ/ -u XXX_remote/master
git commit -m "Imported XXX as a subtree."
git remote rm XXX_remote
git push

http://stackoverflow.com/a/8396318/135441

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