Often, I execute git reset --hard along with git clean -f
in order to clean-up my branch from modifications and build files.
This command, deletes all the untracked files, which is OK for me, but there are few files I want to stay, such as .project or .settings (for eclipse)
These file are not part of the repository, and declared in the .gitignore file. is there a way to keep these files when issuing the above commands, or maybe I should you different commands for that ?
git reset --hard is a classic command in this situation - but it will only discard changes in tracked files (i.e. files that already are under version control). To get rid of new / untracked files, you'll have to use git clean !
Note that git clean -f should only removed files unknown to git, not ignored files.
Only git clean -f -x would removed ignored files. 
(in all cases, a git clean -n -... is better, to have a preview of what would be removed)
The advantage of git reset over git clean is mainly about moving HEAD and resetting the index as well as the working tree.git clean is only about the working tree.
git reset will not touch ignored files. It works with HEAD pointer and index, mostly. But git clean is the evil:
Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.
So the answer is: do not use git clean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With