Documentation
¶
Overview ¶
Command ghbranch deletes remote branches, the one repository write that had no fleet program: `gh api -X DELETE .../git/refs/heads/<b>` and `git push --delete` are refused by guard-bash and name this tool.
ghbranch <owner/repo> delete <branch>... [--dry-run] [--force-unlanded]
Every branch is checked BEFORE any is deleted (all or nothing), and a branch is refused when it is
- the repository's default branch,
- protected,
- the head of an open pull request, or
- unlanded: its head is not contained in a merged or closed pull request from that branch, and is not already reachable from the default branch. --force-unlanded waives only this last check.
After each delete the branch is read back and must answer 404.
The token is read from a 0600 file and sent only in the Authorization header, over https, with redirects refused.
References (read 2026-11-28):
https://docs.github.com/en/rest/branches/branches#get-a-branch GET /repos/{o}/{r}/branches/{b}: 200 {protected, commit.sha}, 404
https://docs.github.com/en/rest/pulls/pulls#list-pull-requests GET /repos/{o}/{r}/pulls?state=all&head={o}:{b}: number, state, merged_at, head.sha
https://docs.github.com/en/rest/commits/commits#compare-two-commits GET /repos/{o}/{r}/compare/{base}...{head}: status ahead|behind|identical|diverged
https://docs.github.com/en/rest/git/refs#delete-a-reference DELETE /repos/{o}/{r}/git/refs/heads/{b}: 204, 422