You may not necessarily want/need to stash your work/files in your working directory but instead simply get rid of them completely. The command git clean
will do this for you.
Some common use cases for doing this would be to remove cruft that has been generated by merges or external tools or remove other files so that you can run a clean build.
Keep in mind you will want to be very cautious of this command, since its designed to remove files from your local working directory that are NOT TRACKED. if you suddently change your mind after executing this command, there is no going back to see the content of the files that were removed. An alternative which is safer is to execute
git stash --all
which will remove everything but save it all in a stash. This stash can then later be used.
However, if you truly DO want to remove all the files and clean your working directory, you should execute
git clean -f -d
This will remove any files and also any sub-directories that don't have any items as a result of the command. A smart thing to do before executing the git clean -f -d
command is to run
git clean -f -d -n
which will show you a preview of what WILL be removed after executing git clean -f -d
So here is a summary of your options from most aggressive to least aggressive
Option 1: Remove all files locally(Most aggressive)
git clean -f -d
Option 2: Preview the above impact(Preview most aggressive)
git clean -f -d -n
Option 3: Stash all files (Least aggressive)
`git stash --all`