Created
March 9, 2023 16:38
-
-
Save malko/cba4252791c18a3759619d32cd604a11 to your computer and use it in GitHub Desktop.
Extract a git repo from another one using git subtree
This file contains 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 characters
# first create a branch in the parent repo | |
git subtree split -P path/to/folder/toExtract --branch branchName | |
# then create the directory for the external repo | |
mkdir myNewRepo | |
cd myNewRepo | |
git init | |
git remote add tempRemote path/to/parent/repo | |
# only getch what is needed no more to avoid cluttered git reflog in the new repo | |
git fetch --no-tags tempRemote branchName | |
git merge --ff tempRemote/branchName | |
# remove unused remote to avoid mistakes on parent repo | |
git remote remove tempRemote | |
# that's it the new repo is not cluttered | |
# if all is good you can remove the branch from parent Repo | |
# and git rm the folder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment