Delete a remote branch

Destructive
What do risk levels mean?
Read-only
Inspects state without changing anything.
Low risk
Reversible with a routine follow-up command.
Medium risk
Changes state; undo path documented.
Destructive
Deletes or overwrites; confirmation required.

Removes a branch from the remote repository, typically after its pull request has merged. The local branch of the same name is untouched.

gitbranchremotedelete

Confirmation required

This recipe is destructive and requires confirmation — confirm you understand the impact before running any command below.

Parameters

Name of the remote branch to delete.

Name of the remote the branch lives on.

Commands

Confirm the branch exists on the remote before deleting it

git ls-remote --heads origin <branch_name>

Delete the branch from the remote repository

git push origin --delete <branch_name>

Verification

git ls-remote --heads origin <branch_name>

No output; the branch is gone from the remote.

Undo

Re-publish the branch from the local copy, if one still exists

git push origin <branch_name>

Pitfalls

  • Undo only works while a local copy of the branch still exists; without one the commits may be unrecoverable.
  • Other people's clones keep their copy until they prune; deletion does not propagate automatically.
  • Protected branches cannot be deleted this way; the push is rejected by the server.

Related