How to delete a branch from git?

Deleting local branch

To delete a local git branch, you can use one of the following

git branch -d <branch_name>
git branch -D <branch_name>
  • -d flag is used as an alias for --delete, it will delete the branch only if this branch has been merged in the upstream branch
  • -D flag is used as an alias for --delete --force, which will delete the branch irrespective of merge status.

Deleting remote branch

To delete a remote branch you can use one of the following:

git push <remote_name> --delete <branch_name>
git push <remote_name> :<branch_name>