Your Guide to How To Delete a Branch Git

What You Get:

Free Guide

Free, helpful information about Files, Data & Cloud Storage and related How To Delete a Branch Git topics.

Helpful Information

Get clear and easy-to-understand details about How To Delete a Branch Git topics and resources.

Personalized Offers

Answer a few optional questions to receive offers or information related to Files, Data & Cloud Storage. The survey is optional and not required to access your free guide.

How to Delete a Branch in Git (Local and Remote)

Deleting a branch in Git is a normal part of keeping your projects tidy. After you merge a feature, fix a bug, or abandon an experiment, you usually don’t need that branch hanging around forever.

This guide walks through how to delete Git branches safely, both on your own machine (local) and on a shared server like GitHub, GitLab, or Bitbucket (remote). We’ll explain what’s happening behind the scenes, where you need to be careful, and which factors change the exact commands you run.

What is a Git Branch, Really?

In simple terms, a Git branch is just a named pointer to a commit.

  • Git stores your history as a chain of commits.
  • A branch name (like main or feature/login) simply points to one of those commits.
  • When you add new commits on that branch, the pointer moves forward.

So when you delete a branch, you’re not instantly throwing away your code. You’re:

  • Removing the label (branch name).
  • Leaving the actual commits in the repository until Git eventually decides they’re unreachable and can be cleaned up.

That’s why it’s often safe to delete a branch after its work has been merged into another branch like main or develop.

Local vs Remote Branches: Know What You’re Deleting

There are two main types of branches you’ll deal with:

Type of branchWhere it livesExample nameTypical use
Local branchOn your computer onlyfeature/searchDaily development, experiments
Remote branchOn a server (GitHub, etc.)origin/feature/uiShared with your team, CI builds

Deleting a local branch only affects your copy of the repo.

Deleting a remote branch removes it from the shared server so others don’t see it either (unless they already have local copies).

You often do both:

  1. Merge a feature into main.
  2. Delete the remote feature branch (so it’s not cluttering the server).
  3. Delete your local feature branch (so it’s not cluttering your machine).

How to Delete a Local Git Branch

You can delete a local branch with the git branch command.

Safe delete: after a branch is merged

If your branch has already been merged into the current branch (often main), use: