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)

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

Questions on Software Engineering Stack Exchange are expected to relate to software engineering within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.


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:


  • 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

Not the answer you're looking for? Browse other questions tagged or ask your own question.