Git Tip: Removing .gitignore’d Files after adding to .gitignore

Very handy trick for removing .gitignore’d files from a repo AFTER those files previously had been included in the repo:

git rm --cached `git ls-files -i --exclude-from=.gitignore`

Now commit the deletion(s):

git commit -m 'Repo pruned - Removed all files that are in the .gitignore'

And if you need to sync with a remote, push it:

git push origin master

And PRESTO – repo is cleaned up without modifying files.

h/t Blundell here

This entry was posted in Development and tagged , by Cornel. Bookmark the permalink.
Cornel

About Cornel

Chief Web Engineer and co-founder of 3PRIME, LLC. I'm always happy to discuss your project's goals. Interested in working together? Get in touch to see if 3PRIME is a fit for your organization.

Comments are closed.