Skip to content

Instantly share code, notes, and snippets.

@tbeseda
Last active August 11, 2022 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbeseda/808bb92754161e8032b6cf59fdbc5919 to your computer and use it in GitHub Desktop.
Save tbeseda/808bb92754161e8032b6cf59fdbc5919 to your computer and use it in GitHub Desktop.
My gitclean command. Prompts if you'd like to proceed with delete.
# uses gum: https://github.com/charmbracelet/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
else
echo "Still dirty."
fi
}

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