Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Created October 13, 2025 13:46
Show Gist options
  • Select an option

  • Save wilcorrea/24ed6e6d4a26fdcc5c651196e4a7b6c9 to your computer and use it in GitHub Desktop.

Select an option

Save wilcorrea/24ed6e6d4a26fdcc5c651196e4a7b6c9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Disable git pager
export GIT_PAGER=cat
untracked=$(git clean -d --dry-run)
changes=$(git status --short)
if [ -z "$untracked" ] && [ -z "$changes" ]; then
echo "Nothing to purge, working tree clean"
exit 0
fi
git status
echo ""
read -p "Purge working tree? (y/N) " confirm
if [ "$confirm" = "y" ]; then
git clean --force -d
git reset --hard
echo "Working tree purged"
else
echo "Operation cancelled"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment