Last active
May 28, 2025 21:05
-
-
Save martinbuberl/b58fd967f271f32f51f50aee62e7332c to your computer and use it in GitHub Desktop.
Revisions
-
martinbuberl revised this gist
Mar 27, 2025 . 1 changed file with 24 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Import an Existing Git Repository into Another ## Before: Folder Structure (Two Separate Repositories) ``` XXX @@ -11,26 +11,33 @@ YYY |- (project files) ``` ## After: Folder Structure (XXX Imported into YYY as a Subdirectory) ``` YYY |- .git <-- This now contains the full change history from XXX |- ZZZ <-- This was originally XXX, now a subdirectory of YYY |- (project files) |- (project files from YYY) ``` ## Steps to Import Run the following commands inside **YYY** to import **XXX** as a subtree: ```sh git remote add XXX_remote <path-or-url-to-XXX-repo> # Add XXX as a remote git fetch XXX_remote # Fetch history from XXX git merge -s ours --no-commit XXX_remote/master # Merge without modifying YYY's files git read-tree --prefix=ZZZ/ -u XXX_remote/master # Move XXX into subdirectory ZZZ git commit -m "Imported XXX as a subtree." # Commit the changes git remote rm XXX_remote # Remove temporary remote git push # Push changes to the repository ``` ### Explanation - **Preserves full commit history** of XXX. - **Places XXX’s files inside `ZZZ/`** within YYY. - **Does not modify YYY’s existing files** during the merge. [Source: Stack Overflow](http://stackoverflow.com/a/8396318/135441) -
martinbuberl revised this gist
Oct 25, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,6 +29,8 @@ 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 -
martinbuberl revised this gist
Oct 25, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ YYY 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 -
martinbuberl revised this gist
Oct 25, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ YYY In YYY: ```sh git remote add XXX_remote <path-or-url-to-XXX-repo> git fetch XXX_remote git merge -s ours --no-commit XXX_remote/master -
martinbuberl renamed this gist
Oct 25, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
martinbuberl renamed this gist
Oct 25, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
martinbuberl renamed this gist
Oct 25, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
martinbuberl renamed this gist
Oct 25, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
martinbuberl renamed this gist
Oct 25, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
martinbuberl renamed this gist
Oct 25, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Import existing Git repository into another Folder structure before (2 separate repositories): ``` -
martinbuberl renamed this gist
Oct 25, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
martinbuberl created this gist
Oct 25, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ 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." ``` http://stackoverflow.com/a/8396318/135441