/github-for-non-tech

How to delete a branch in GitHub?

Learn step-by-step how to delete a GitHub branch locally and remotely, manage permissions, and clean up pull requests effectively.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to delete a branch in GitHub?

 
Step 0: Ensure you have the necessary permissions
 

Before you delete any branch on GitHub, confirm that you have write or admin access to the repository. Without the correct permissions, you will not see the delete option.

 
Step 1: Identify the branch you want to delete
 

First, determine which branch needs to be removed. You can do this either on the GitHub website or in your local repository.

On the GitHub website:

  • Navigate to your repository’s main page.
  • Click the Branch dropdown (above the file list) to view all branches.

In your local repository:

git branch

This command lists all local branches and highlights the current one.

 
Step 2: Delete the branch locally (optional)
 

If you have the branch checked out or already fetched locally and want to remove it from your machine, run:

git branch -d branch-name

If Git prevents deletion due to unmerged changes, force deletion with:

git branch -D branch-name

Note: Deleting a local branch does not affect the remote branch on GitHub.

 
Step 3: Delete the branch on the GitHub website
 

To remove the branch directly in the web interface:

  • Go to your repository on GitHub.
  • Click the Branches tab (usually found above the file list or under Code).
  • Locate the branch you want to delete in the list.
  • Click the trash can icon on the right of the branch row.
  • In the confirmation dialog, click Delete branch.

 
Step 4: Delete the branch using Git command line
 

If you prefer the command line or need to automate the process, you can delete a remote branch with:

git push origin --delete branch-name

After running this, you should see output similar to:

To github.com:username/repo.git
- [deleted]         branch-name

 
Step 5: Verify that the branch has been deleted
 

Make sure the branch no longer exists both locally and remotely.

Check on GitHub website:

  • Refresh the Branches page—your branch should be gone.

Check from your local machine:

git fetch --prune
git branch -r
  • The remote branch list should no longer include origin/branch-name.

 
Step 6: Clean up any references in pull requests
 

If you opened a Pull Request from the deleted branch, you may wish to close it since the source branch is gone.

  • Go to the Pull requests tab in your repository.
  • Filter by your branch name or look for the PR title.
  • Click Close pull request (do not merge if branch is deleted).

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022