Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Questions on Programmers Stack Exchange are expected to relate to software development 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.

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
up vote 4 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

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