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 initin each of those directories. Add ashiledgoal to yourMakefile:
.PHONY: shield
shield:
@git init .idea
@git init env
@git init secrets
-
Make sure to execute
make shieldafter cloning the repository! -
Now you can run
git clean -fdxall you want! Add it to yourMakefiletoo:
.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!