How to delete a remote Git branch

Deleting a remote Git branch is not as obvious as deleting a local branch. Following best practices when creating separate branches for each issue, you’ll end up with a lot of old branches both on local and remote Git repo. Here’s how to delete both remote and local branches.

Learn how to delete a remote Git branch

Deleting Remote Branch:

Branch name example: 32-hotfix. Origin being the name of the remote repo.

git push origin --delete 32-hotfix

Deleting Local Branch:

Soft Delete (merged):

git branch -d 32-hotfix

Forced Delete (unmerged):

git branch -D 32-hotfix

Sometimes when listing the branches (git branch -a) you’ll still see the previously deleted branch. Even though they don’t exist, you’ll still need to ‘prune’ the list in order for it to update to the latest branches. You can check my other post on how to prune Git branch list.
Credit to: https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-remotely

Justin Mathew

A front end web developer specializing in HTML/CSS, JS, PHP & MySQL with over 10 years experience in the web development field.