Last Updated: March 14, 2016
·
346
· sprt

Remove .gitignore'd files

Here is how to remove files and directories that are ignored by git (cf. .gitignore). May be useful following a test run, a build, etc.

$ git clean -dfX

Options:

  • -d: Remove directories in addition to files.
  • -f: Force removal. Will refuse to remove anything if not provided.
  • -X: Remove only files that are present in .gitignore.

See git-clean(1).

1 Response
Add your response

Note that this will remove the files from the file system, not from git tracked repository.

If you want to remove files from the git repository which are .gitignore'd (technically: to unstage and remove paths only from the index) you can run this command:

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

And tun this command to see first which files will be removed from repository:
git ls-files -i --exclude-from=.gitignore

over 1 year ago ·