Skip to content

Instantly share code, notes, and snippets.

Last active Aug 11, 2022
What would you like to do?
My gitclean command. Prompts if you'd like to proceed with delete.
# uses gum:
gitclean() {
DIRTY=$(git clean -Xdn | sed 's/Would remove //g')
gum style \
--foreground 196 --border thick --border-foreground 88 \
--margin "1 2" --padding "1 3" "$DIRTY"
gum confirm "🧹 Delete these?" \
&& git clean -Xdf \
|| echo "Still dirty."
# simple zsh
gitclean() {
git clean -Xdn
if read -q REPLY\?"Clean these? (Y/y)"; then
git clean -Xdf
echo "Still dirty."

git clean helps remove untracked files.

I used to run git clean -Xdn to list files that would be removed, then git clean -Xdf to remove them.
This is hard to remember and error prone. Try one of these shell commands to simplify this useful series.

The "gum" version of gitclean looks like:

gitclean output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment