Delete a GitHub gist safely with gh gist delete
You will remove one GitHub gist with the GitHub CLI, while keeping the destructive choice visible and checking that you selected the right object. Allow about five minutes for a known gist ID, or ten minutes if you need to identify it from your gists. The examples use gh 2.87.3, installed here on 23 September 2026.
The route
Jump straight to the step you need, or tick off Done means at the end.
This command needs an authenticated gh session with permission to delete the gist. It normally runs as your ordinary user. Do not use sudo: changing the user can make gh read a different configuration and credential store.
1. Check the installed command
Confirm which executable will run and read its local help:
$ command -v gh
/usr/bin/gh
$ gh --version
gh version 2.87.3 (2026-02-23)
$ gh gist delete --help
The installed synopsis is gh gist delete {<id> | <url>} [flags]. It accepts one gist ID or URL, or no argument for an interactive selection. The only command-specific option in this version is --yes, which confirms deletion without prompting.
Checkpoint
Stop here if the version, path or account is not the one you expected. The command changes a remote GitHub object, not a local file.
2. Identify the gist before deleting it
Use a full gist URL or its ID. A URL is often safer when you are copying from a browser because it leaves the owner and selected page visible during review:
$ gh gist view https://gist.github.com/EXAMPLE_OWNER/0123456789abcdef0123456789abcdef
Replace EXAMPLE_OWNER and the hexadecimal value with the real values. The view command is only a check; it does not delete anything. If you already have a verified ID, you can use it directly. Do not guess an ID or paste a repository URL that is not a gist URL.
For an interactive choice, leave the selector empty and let gh retrieve your gists:
$ gh gist delete
The command presents a selection and then asks for confirmation using the gist's filename. Choose the exact gist, read the confirmation question, and answer yes only when its identity is clear. With no gists available, the current implementation reports No gists found. and makes no deletion.
3. Delete interactively when working at a terminal
The safest normal form is an explicit, verified selector without --yes:
$ gh gist delete https://gist.github.com/EXAMPLE_OWNER/0123456789abcdef0123456789abcdef
? Delete "notes.txt" gist? Yes
✓ Gist "notes.txt" deleted
The exact success marker can vary with the terminal colour scheme, but the useful text is that the named gist was deleted. Pressing no at the prompt cancels the operation and returns a cancellation error. Treat that as a successful safety outcome, not as proof that a deletion happened.
Warning
Deletion is a remote, destructive action. GitHub CLI sends a delete request for the gist after confirmation. There is no undo option in gh gist delete, and this guide does not assume that an external backup or cached copy exists.
4. Use --yes only in a reviewed script
Non-interactive jobs cannot answer a prompt. Pass both a verified ID or URL and --yes:
gist_url='https://gist.github.com/EXAMPLE_OWNER/0123456789abcdef0123456789abcdef'
gh gist delete "$gist_url" --yes
Do not replace the placeholder with a value obtained from an unreviewed command substitution or an ambiguous search result. The flag suppresses the final confirmation; it does not provide a second safety check. Keep the selector in a reviewed configuration or an argument supplied by an operator.
A non-interactive invocation without --yes fails before deletion because it cannot prompt. A non-interactive invocation with no selector also fails: the command requires an ID or URL when it cannot present an interactive choice.
5. Check the result and diagnose failures
When standard output is a terminal, a successful deletion prints the gist filename. The exit status is the better signal for a script:
if gh gist delete "$gist_url" --yes; then
printf '%s\n' 'Gist deletion completed'
else
status=$?
printf 'Gist deletion failed with status %s\n' "$status" >&2
exit "$status"
fi
If the command says that the gist was not found or is not owned by you, check the URL, the active GitHub account and the hostname in your gh configuration. A valid-looking ID is not evidence that the current account owns the gist. Authentication or network errors must also be fixed before retrying.
After a successful deletion, the same gist URL should no longer display the gist to you. That is a remote check and may show an HTTP or GitHub error page rather than a useful shell message. Do not repeatedly retry a deletion after a timeout until you have checked whether the gist is already gone; a timeout does not tell you whether the server received the request.
6. Preserve a copy when recovery matters
There is no recovery command in this workflow. If the content may be needed later, save it before deletion. For a text gist, view or copy its raw content into a deliberately named local file, then inspect that file before proceeding:
$ gh gist view https://gist.github.com/EXAMPLE_OWNER/0123456789abcdef0123456789abcdef --raw > gist-backup.txt
$ test -s gist-backup.txt && echo 'Backup is non-empty'
Backup is non-empty
The raw form may contain more than one file depending on the gist, so check the backup rather than assuming one filename. A backup is only a local copy, not a way to restore the original gist's history, visibility or URL. If you must retain those properties, do not delete the gist until you have an independently tested replacement plan.
Done means
- The installed
ghversion and authenticated account were checked. - The gist ID or URL was reviewed, and its contents or filename identified the intended object.
- Interactive deletion used the confirmation prompt, or a reviewed non-interactive call used
--yeswith an explicit selector. - The command exit status and, where practical, the remote URL were checked.
- A local backup was made first when the deleted content could not be recreated.