Lowercase -x and uppercase -X do very different things in git clean. The uppercase one is the safer cleanup when you only want build junk gone.
git clean -n -d -X
git clean -f -d -X
-X removes only files that your .gitignore rules ignore: build folders, logs, caches. Untracked files that aren’t ignored, like a new source file you haven’t added yet, are left alone. Lowercase -x is the opposite of careful: it removes ignored and untracked files together.
The first line is a dry run thanks to -n; it prints Would remove build/ and so on. The second line does it for real. -d includes directories. Without it, git skips ignored folders and only lists loose files, which is confusing when build/ doesn’t show up.
It’s a quick way to get back to a fresh state without cloning again, a bit like a make clean that knows about every tool.
I’d always read the dry run before adding -f. Ignored files aren’t always junk: a local .env, a database file or editor settings are often ignored too, and git clean deletes them without a copy. There’s no undo. Use -e to keep a pattern, for example git clean -f -d -X -e '!.env', or move such files elsewhere first.
Further reading: git-clean documentation