Data report"State of code review 2024" is now liveRead the full report

How to delete a branch in GitHub

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


This guide provides detailed instructions on how to delete Git branches, both locally and remotely hosted on GitHub, ensuring your project remains organized and efficient.

In Git, branches are pointers to a specific commit in a repository. Deleting a branch removes this pointer, which can help in reducing clutter and focusing on currently active development tasks. This is particularly useful after merging feature branches into the main branch, where the feature branch is no longer needed.

Before deleting a branch remotely, you might want to delete it from your local repository.

Ensure you are not currently on the branch you wish to delete. Switch to another branch using the checkout command:

Terminal
git checkout main

To delete the branch locally, use the following Git command:

Terminal
git branch -d <branch-name>

Replace <branch-name> with the name of the branch you wish to delete. If the branch has changes that have not been merged, you will need to use the -D flag instead to force deletion:

Terminal
git branch -D <branch-name>

After deleting the branch locally, you need to push the deletion to GitHub to update the remote repository:

Terminal
git push origin --delete <branch-name>

This command tells Git to remove the branch from the remote repository as well.

Log into your GitHub account and go to the repository from which you want to delete the branch.

On the repository page, click on the “Branches” link near the top of the page. This will display a list of all the branches in the repository.

Find the branch you wish to delete in the list. You can use the search bar to quickly find the branch by typing its name.

Next to the branch name, you’ll see a trash can icon. Click this icon to delete the branch. GitHub will ask you to confirm the deletion. Confirm it, and the branch will be permanently removed from the repository. Caveat: the branch may still be accessible under certain conditions. Specifically, if there are any open pull requests associated with the branch or if someone has a local copy of it, the branch can still technically be accessed or even restored. Therefore, while the branch is removed from the visible list on GitHub, its existence may persist in these other forms until all references are fully cleared or merged.

For further reading see the official Git documentation.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2