Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

How do I delete a Git branch?

By M.K. Verma · 29 April 2022

How do I delete a Git branch?

It's very easy:

To delete the remote branch

git push -d origin <branch-name>

Or

git push origin :<branch-name>

-- You can also delete tags with this syntax

To forcefully delete the local branch

git branch -D <branch-name>

Note: do a git fetch --all --prune on other machines after deleting remote branch, to remove obsolete tracking branches.

Example

to remove the local branch

git branch -D my-local-branch

to remove the remote branch

git push origin :my-remote-branch

TIP: if you want to see all available branches you can use git branch -a,

and to see just remote branches, you can use git branch -r