How to Delete a Branch in Git: Local, Remote, and GitHub
Run git branch -d <branch-name> to delete a local branch that's already merged, or git branch -D <branch-name> to force-delete one that isn't. Deleting a remote branch is a separate step - git push origin --delete <branch-name> - since local and remote branches are independent objects.
Deleted the wrong branch? On the command line you're stuck recovering it via git reflog; in Tower it's just Cmd+Z. Below: remote deletion, GitHub's web UI, and cleaning up stale tracking references after a teammate deletes theirs.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Deleting a local branch
Use the git branch command with the -d flag:
$ git branch -d <local-branch>
Git will refuse this if the branch contains commits that haven't been merged or pushed yet — a safety net against accidental data loss. To override that and force-delete the branch anyway, use the -D flag:
$ git branch -D <local-branch>
Use -D with care: it permanently discards any unmerged commits on that branch.
Note that you cannot delete the branch you currently have checked out. Switch to another branch first (e.g., git checkout main) before running the delete command.
Deleting a remote branch
To delete a remote branch, you use git push with the --delete flag instead of git branch. Before you delete anything, it's a good idea to confirm the exact name of the remote branch with git branch -r, which lists all remote branches your local repository knows about — trying to delete a branch that doesn't exist on the remote only produces an unhelpful error message:
$ git branch -r
origin/feature/login
origin/main
Once you've verified the branch name, run the delete command:
$ git push origin --delete feature/login
Git also accepts an older shorthand for the same operation — a colon in front of the branch name:
$ git push origin :feature/login
The empty source before the colon tells Git to push "nothing" to that remote branch, which effectively deletes it. Both commands are equivalent; --delete is simply more explicit and easier to remember.
Either way, this only removes the remote branch. Your local branch with the same name is unaffected and must be deleted separately with git branch -d.
After a collaborator has deleted a remote branch, everyone else should run git fetch --prune (or git remote prune origin) to remove their stale local references to that branch.
Deleting a branch on GitHub
GitHub's web interface lets you delete remote branches without touching the command line. Navigate to your repository and click the Branches link, then click the trash icon next to the branch you want to remove:
You can also delete a branch directly from a pull request page once it has been merged — GitHub shows a "Delete branch" button at the bottom of the PR.
Note that GitHub only lets you delete remote branches this way. To remove the corresponding local branch on your machine, you still need to run git branch -d <branch-name> in your terminal.
No Command Line Needed
Deleting (and Undoing) Branches in Tower
In case you are using the Tower Git client, you can delete any branch by right-clicking it in the sidebar and choosing the "Delete…" option. And if you change your mind, just press CMD+Z (or CTRL+Z on Windows) to instantly undo the deletion and restore the branch:
Can I undo deleting a branch?
In most cases, yes — as long as you act before Git's garbage collector runs (typically after 30 days).
On the command line, use git reflog to find the SHA of the last commit on the deleted branch, then recreate it:
$ git checkout -b <branch-name> <commit-hash>
Learn more about this technique in our free First Aid Kit for Git video series.
No Command Line Needed
Undoing a Branch Deletion in Tower
If you're using the Tower Git client, simply press CMD+Z (or CTRL+Z on Windows) to undo the deletion immediately — no reflog spelunking needed.
Learn More
- Check out the chapter Deleting Branches – Command Line edition in our free online book
- Check out the chapter Branching can Change Your Life – Desktop GUI edition in our free online book
Download the Cheat SheetFree
Get 18 of our most popular Cheat Sheets in one handy ZIP!

Thanks! Please Check Your Inbox!
Want to win one of our awesome Tower shirts?
Tell your friends about the package!
