Skip to content

Instantly share code, notes, and snippets.

@floydnoel
Last active March 29, 2024 19:59
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save floydnoel/2f4ab07460c2717e84dbad933f208f8a to your computer and use it in GitHub Desktop.
Save floydnoel/2f4ab07460c2717e84dbad933f208f8a to your computer and use it in GitHub Desktop.
Remove all files from a Git repo based on the .gitignore file
#!/bin/bash
echo "Cleaning up any git ignored files..."
# copy and paste the line below to get the same results as running this script
git rm --cached `git ls-files -ic --exclude-from=.gitignore`
echo "Finished clean up."
# source: https://stackoverflow.com/questions/13541615/how-to-remove-files-that-are-listed-in-the-gitignore-but-still-on-the-repositor/13541721
@Lauro235
Copy link

This is a beautiful thing.

@Bond-Addict
Copy link

This works perfectly. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment