Skip to content

Instantly share code, notes, and snippets.

@olavmrk
Last active August 23, 2021 21:33
Show Gist options
  • Save olavmrk/9383860 to your computer and use it in GitHub Desktop.
Save olavmrk/9383860 to your computer and use it in GitHub Desktop.
git filter-branch command to remove all files except those of interest
# Remove every file except "./somefile.txt" and the directory "./somedir".
# --prune-empty to remove empty commits.
git filter-branch --tree-filter "find . -not -path './.git' -not -path './.git/*' -not -path './somefile.txt' -not -path './somedir/*' -not -path './somedir' -delete" --prune-empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment