Skip to content

Instantly share code, notes, and snippets.

@warengonzaga
Created October 2, 2025 20:45
Show Gist options
  • Select an option

  • Save warengonzaga/6d335e5ff7e66334d1739c652aa5bbf8 to your computer and use it in GitHub Desktop.

Select an option

Save warengonzaga/6d335e5ff7e66334d1739c652aa5bbf8 to your computer and use it in GitHub Desktop.
GitHub CLI commands to delete all labels from a repository - different approaches and methods

GitHub CLI: Delete All Labels

This gist provides different approaches to delete all labels from a GitHub repository using the GitHub CLI (gh).

Why the obvious approach doesn't work

# ❌ This doesn't work - gh doesn't support wildcards
gh label delete *

The GitHub CLI doesn't support wildcard deletion, so we need alternative approaches.

✅ Working Solutions

Option 1: One-liner with auto-confirmation (Recommended)

gh label list --json name --jq '.[].name' | xargs -I {} gh label delete {} --yes

What this does:

  • gh label list --json name - Gets all labels in JSON format with only the name field
  • --jq '.[].name' - Extracts just the label names using jq
  • xargs -I {} gh label delete {} --yes - Runs delete command for each label with auto-confirmation

Option 2: Preview first, then delete

# First, see what labels exist
gh label list

# Then delete all labels
gh label list --json name --jq '.[].name' | xargs -I {} gh label delete {} --yes

Option 3: Manual confirmation for each label

gh label list --json name --jq '.[].name' | xargs -I {} gh label delete {}

This will prompt you to confirm each deletion individually.

Option 4: Store names in a file first

# Save label names to a file
gh label list --json name --jq '.[].name' > labels.txt

# Review the file
cat labels.txt

# Delete all labels from the file
cat labels.txt | xargs -I {} gh label delete {} --yes

# Clean up
rm labels.txt

Prerequisites

  • GitHub CLI (gh) must be installed and authenticated
  • You need admin permissions on the repository
  • jq must be installed for JSON parsing

Error Handling

If some labels fail to delete, you can identify which ones remain:

# Check remaining labels
gh label list

# Delete specific labels manually
gh label delete "label-name" --yes

Restoring Default Labels

If you want to restore GitHub's default labels after deletion:

# GitHub doesn't have a built-in restore, but you can recreate common ones
gh label create "bug" --description "Something isn't working" --color "d73a4a"
gh label create "enhancement" --description "New feature or request" --color "a2eeef"
gh label create "documentation" --description "Improvements or additions to documentation" --color "0075ca"

Tips

  • Always run gh label list first to see what you're working with
  • Consider backing up your labels before mass deletion
  • The --yes flag skips confirmation prompts - use carefully
  • If you have many labels, the operation might take a few seconds

Created for efficient GitHub repository management

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