brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: preview what git clean will delete with -n

Git
~/tips/tip-git-clean-dry-run

git clean -n -d

Shows which untracked files git clean would remove, without deleting anything.

git clean deletes files that git does not track. There is no undo. That is why it deserves a dry run.

git clean -n -d

-n (or --dry-run) only shows what would be removed and deletes nothing. -d includes untracked directories, because by default git does not recurse into them. Read the list. If it matches what you expect, run the real thing:

git clean -f -d

By default git refuses to delete without -f, thanks to the clean.requireForce setting, which is on unless you changed it. The dry run ignores that setting because nothing is deleted anyway.

Add -x and git also removes files that are in your .gitignore, so build output, caches, and possibly the local config file with your passwords in it. The docs mention this as a way to get a pristine tree for a clean build.

The caveat: files removed by git clean never went through git, so no reflog can bring them back. And a nested git repository inside your project needs a second -f before git touches it.

Further reading: git clean documentation, On this site: git diff –staged shows what your commit will contain, On this site: put -delete last in find, or it deletes more than you think

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link