Skip to content

Instantly share code, notes, and snippets.

@talayhan
Forked from martinbuberl/git-import-repository.md
Created February 24, 2019 12:42
Show Gist options
  • Save talayhan/17394f4a8dba3abffb9ec84626e3d3ae to your computer and use it in GitHub Desktop.
Save talayhan/17394f4a8dba3abffb9ec84626e3d3ae 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