Skip to content

Instantly share code, notes, and snippets.

@mkows
Last active September 29, 2021 06:59
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 mkows/3bd1cd7ee25f8fa9f42aef629ef6fe82 to your computer and use it in GitHub Desktop.
Save mkows/3bd1cd7ee25f8fa9f42aef629ef6fe82 to your computer and use it in GitHub Desktop.
git - extract a directory into a separate repository
# using:
# - git filter-branch OR
# - git filter-repo
# extract folder into a new repo
git clone git@github.com:__ORG__/__PROJECT__.git __LOCAL_ALIAS_DIR__
cd __LOCAL_ALIAS_DIR__
git co -b main
git filter-branch --prune-empty --subdirectory-filter __DIR_TO_EXTRACT__ main
# create __PROJECT_NEW__ repo in github and then:
git remote set-url origin git@github.com:__ORG__/__PROJECT_NEW__.git
git branch -M main
git push -u origin main
# or if you want to keep the original dir intact:
https://github.com/newren/git-filter-repo
git filter-repo --path __DIR_TO_EXTRACT__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment