Git - clean repo from untracked files

Sometimes, we need to clean up the local environment from files created during the build process - like obj and dbg folders and their content created during the build of .NET solutions in Visual Studio.

Sure, we can run the "Clean" command directly from Visual Studio, but this won't remove all files - we may still have some "leftovers" from running the tests or other temporary files.

Last, but not least we may want to have clean branch.

If we are working with git we can do it with a single command.

git clean -dfx

Note: this command will remove all none tracked files - all objects that are not part of the repository.

That's it. I'm using this command quite often, mostly when on the same repository I'm switching among different versions/branches to make sure I have always a clean build.