Skip to content

Instantly share code, notes, and snippets.

@holms
Created July 25, 2013 10:21
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 holms/6078511 to your computer and use it in GitHub Desktop.
Save holms/6078511 to your computer and use it in GitHub Desktop.
Create repository from git subdirectory
git clone /XYZ /ABC # To clone your local repository
cd ABC
git remote rm origin
# only rewrite the HEAD branch and ignore tags and other branches
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter subdirectory_to_repo HEAD
# then delete the backup reflogs so the space can be truly reclaimed (although now the operation is destructive)
git reset --hard
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --aggressive --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment