How to delete a Git branch (local and remote)

Delete a merged local branch with git branch -d <name>. Use -D to force-delete an unmerged one. To delete it on GitHub too, run git push origin --delete <name>.

Step by step

  1. Switch away from the branch first:

    $ git switch main
  2. Delete it locally:

    $ git branch -d croissant
  3. Delete it on GitHub:

    $ git push origin --delete croissant

Deleting a merged branch only removes the label: its commits stay in main's history.

Try it in the interactive sandbox →Practice “Clean up” with a real repository and teammates, right in your browser.

Related guides