Remove unwanted files from a git repo AFTER adding a .gitignore. The files will remain on disk. This article provides a script to remove files from a Git repository that were committed before a `.gitignore` file was added. The commands use `git ls-files` to identify and un-track files matching the ignore rules, followed by a commit to finalize the removal. The files themselves remain on the local disk. git-ignore.sh This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters I just ran into this after initializing a Visual Studio project before adding a .gitignore file like an idiot . I felt real dumb commiting a bunch of files I didn't need to, so the commands below should do the trick. The first two commands came from the second answer on this post: http://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files See the unwanted files: git ls-files -ci --exclude-standard Remove the unwanted files: git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached Commit changes git commit -am " Removed unwanted files marked in .gitignore " Push git push origin master or whatever branch you're on