Skip to content

Instantly share code, notes, and snippets.

@jacklund
Created May 13, 2013 00:18
Show Gist options
  • Save jacklund/5565462 to your computer and use it in GitHub Desktop.
Save jacklund/5565462 to your computer and use it in GitHub Desktop.
Prune out subdirectories from a repository using Git
# Get a list of the directories I'm not interested in
$ excludes=`echo $* | tr " " "|"`
$ files=`ls | egrep -v $excludes | tr "\\n" " "`
# Disconnect from remote for safety
$ git remote rm origin
# Get rid of all tags that don't fit my pattern
$ git tag -l | grep -v $pattern | xargs git tag -d
# Prune the directories I'm not interested in
$ git filter-branch --tag-name-filter cat --prune-empty \
--tree-filter "rm -rf ${files}" -- --all
# Reset the indexes
$ git reset --hard
# Get rid of obsolete references in the logs
$ 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