Skip to content

Instantly share code, notes, and snippets.

@tmattio
Forked from martinbuberl/git-import-repository.md
Created December 3, 2019 15:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmattio/9f7e3cc7b8e1dd4cbc584ad9c1b6eee6 to your computer and use it in GitHub Desktop.
Save tmattio/9f7e3cc7b8e1dd4cbc584ad9c1b6eee6 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 --allow-unrelated-histories -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