git clean -fdx
It removes all files not tracked or staged by git. Useful for cleanup and reverting your project to “factory settings”.
But you might want to keep some directories around, like editor specific caches. You can do this:
- First, add the directory you want to keep in
.gitignore
; it has to be the entire directory, with none of it’s contents tracked:
# Good
/.idea/
/env/
/secrets/
# Bad (Don't do this!)
/secrets/*
!/secrets/.keep
- Now you need to do a
git init
in each of those directories. Add ashiled
goal to yourMakefile
:
.PHONY: shield
shield:
@git init .idea
@git init env
@git init secrets
-
Make sure to execute
make shield
after cloning the repository! -
Now you can run
git clean -fdx
all you want! Add it to yourMakefile
too:
.PHONY: clean
clean:
@git clean -fdx
Pro Tip Link to heading
If your repository and development tools are not git clean -fdx
proof, you
failed at life!