How to Delete Local/Remote Git Branches

techiediaries profile image Ahmed Bouchefra ・1 min read

If you have previously worked with Git for versioning your Angular code, there is a good chance that you had some situation where you wanted to delete a remote branch or multiple branches. This happens many times to developers, particularly in large projects.

In this article, we'll learn:

  • How to delete a local branch in your Git repository,
  • How to delete a remote branch in Git,
  • How to delete all Git branches which have been merged,
  • How to remove all local branches not on remote,
  • How to delete all your local Git branches except master.

Before tackling how to delete a remote branch, we’ll first see how to delete a branch in the local Git repository.

Note: Version control systems are an indispensable tool in modern web development that can help you solve many issues related to every task. Git is one of the most popular version control systems nowadays.

Before we proceed to learn how to delete local and remote branches in Git, let's define what's a Git branch and the side effects of deleting branches.

A branch in Git is a pointer to a commit. If you delete a branch, it deletes the pointer to the commit. This means if you delete a branch that is not yet merged and the commits become unreachable by any other branch or tag, the Git garbage collection will eventually remove the unreachable commits.

Read the full article on Techiediaries

Posted on by:

techiediaries profile

Ahmed Bouchefra


I write about modern frontend and backend technologies.


markdown guide
git branch -d (-D) name
git branch -d (-D) origin name
git remote prune origin