tags:

views:

2501

answers:

3

How can I clear my working directory in git?

+3  A: 
git clean -xdf

Edit: It's not well advertised but git clean is really handy. Git Ready has a nice intro to git clean.

Dev er dev
+3  A: 

What do you mean with "clear"?

rm -rf

Or do you want to reset your working copy to the latest repository version?

git reset --hard
Lennart
+11  A: 

To reset a specific file to the last-committed state (to discard uncommitted changes in a specific file):

git checkout thefiletoreset.txt

This is mentioned in the git status output:

(use "git checkout -- <file>..." to discard changes in working directory)

To reset the entire repository to the last committed state:

git reset --hard

To remove untracked files, I usually just delete all files in the repository (but not the .git/ folder!), then do git reset --hard which leaves it with only committed files.

A better way is to use git clean

git clean -d

..will remove untracked files. You can add the argument -n to perform a dry-run and it will tell you what will be removed.

Relevant links:

dbr