To delete a remote branch in Git, run git push origin --delete branch-name. This removes the branch from the remote repository, such as GitHub. Your local branch of the same name is not touched, so remove it separately with git branch -d branch-name if you no longer need it.
Deleting a branch only removes a pointer, not the commits that were merged. Cleanup is routine after a pull request is merged, but a few details make it safe.
The standard form names the remote and the branch.
An older, equivalent syntax uses an empty source in a refspec, and you may see it in scripts:
Both ask the remote to delete the reference. Git 1.7.0 and later support --delete, so prefer it because it reads clearly.
The remote and local branches are separate. After deleting the remote one, remove the local copy:
-d refuses to delete a branch whose commits are not merged. If you are sure you want to discard unmerged work, use -D:
You cannot delete the branch you are currently on, so switch first with git switch main.
When a teammate deletes a branch on GitHub, your clone still lists origin/feature/old-login. Remove such stale references with prune.
or preview first:
To prune on every fetch, set it once:
Then git branch -r shows only branches that exist on the remote.
You can also delete it in the browser:
After merging a pull request, GitHub shows a Delete branch button. In the repository settings you can turn on Automatically delete head branches, which removes the branch after every merge.
Delete attempts can fail for these reasons.
| Message | Cause |
|---|---|
remote ref does not exist | The branch is already gone, or the name is misspelt. Run git fetch --prune and check git branch -r |
protected branch hook declined | A branch protection rule blocks deletion. Ask an admin to change the rule |
refusing to delete the current branch | It is the default branch of the remote. Change the default branch in the repository settings first |
Permission denied | You do not have write access to the repository |
A deleted branch is not gone immediately. If you still have the local branch or know the commit hash, recreate it:
Find the hash with git reflog on your machine. On GitHub, a branch deleted after a merged pull request has a Restore branch button on that pull request page.
Follow this order when a pull request is merged and you want a tidy repository.
git switch main then git pull.git branch --merged main lists local branches whose work is already included.git push origin --delete feature/old-login.git branch -d feature/old-login.git fetch --prune.To find old remote branches that are already merged into main, use:
Review the list before deleting anything, and never remove main, develop or release branches that your team still uses.
Sometimes you want a different name, not removal. Git has no rename for remote branches, so push the new name and delete the old one.
Tell collaborators, because their local branches that track old-name will show a gone upstream until they run git branch -u origin/new-name.
No. Run git branch -d branch-name locally as a second step.
No. The commits are already part of the branch you merged into. Only the branch name is removed.
List them in one command: git push origin --delete branch-a branch-b.
It is a stale remote-tracking reference. Run git fetch --prune to remove it.
Use git push origin --delete branch-name to remove a branch from the remote, git branch -d for the local copy, and git fetch --prune to clean stale references. Respect branch protection, and remember that merged commits stay safe after the branch name is deleted.