Skip to content

Instantly share code, notes, and snippets.

@exalted
Last active July 9, 2018 02:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save exalted/fc841a4d416c1ce155f1 to your computer and use it in GitHub Desktop.
Save exalted/fc841a4d416c1ce155f1 to your computer and use it in GitHub Desktop.
Given a subdirectory extract separate repo out of an existing one
# Simple
git filter-branch --prune-empty --subdirectory-filter foobar/ --tag-name-filter cat -- --all
# Complex
# (Ref.: http://stackoverflow.com/a/17867910/11895,
# http://stackoverflow.com/a/19957874/11895)
git filter-branch -f --prune-empty --index-filter \
'git rm --cached --ignore-unmatch -r -q -- . ; \
git reset -q $GIT_COMMIT -- .gitignore README.md foo/ bar/' \
-- --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment