Take the 2-minute tour ×

In Mercurial I can do this with the bundled Purge Extension and executing the following command:

hg purge

Also good to get rid of ignored files:

hg purge --all

I'm curious about the most practical/used equivalent solution in git.

Edit: I want to just get rid of the untracked files, not reset everything (e.g. suppose I have a program generating cache files or generated code and I want to delete them with git's help)

share|improve this question

closed as off topic by Mark Booth, ChrisF Oct 19 '12 at 14:25


This question is off-topic on Programmers and would be a duplicate on Stack Overflow, where it should have been asked, see Removing untracked files from your git working copy. –  Mark Booth Oct 19 '12 at 14:20

2 Answers 2

up vote 3 down vote accepted

It's git reset with the option --hard:

git reset --hard

Here is an SO answer which have more details:


And the manual:



To only delete untracked files, use clean


Manual entry:


share|improve this answer
Sorry, made my question a little more specific, I meant only the untracked files –  dukeofgaming Oct 18 '12 at 5:52
I've added git clean. –  jgauffin Oct 18 '12 at 5:54

For all git clean commands, add -n for dry-run.

Clean all untracked files and directories, except ignored files (listed in .gitignore):

git clean -fd

Also clean ignored files:

git clean -fdx

Only clean ignored files (useful for removing build artifacts, to ensure a fresh build from scratch, without discarding new files/directories you haven't committed yet):

git clean -fdX
share|improve this answer
