Skip to content

Instantly share code, notes, and snippets.

@malko
Created March 9, 2023 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malko/cba4252791c18a3759619d32cd604a11 to your computer and use it in GitHub Desktop.
Save malko/cba4252791c18a3759619d32cd604a11 to your computer and use it in GitHub Desktop.
Extract a git repo from another one using git subtree
# 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