Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

1  
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
add comment

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:

http://stackoverflow.com/a/9530204/70386

And the manual:

http://www.kernel.org/pub/software/scm/git/docs/git-reset.html

Edit

To only delete untracked files, use clean

http://stackoverflow.com/questions/61212/removing-untracked-files-from-your-git-working-copy

Manual entry:

http://www.kernel.org/pub/software/scm/git/docs/git-clean.html

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
add comment

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
add comment

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