If you’re working in a repository with lots of activity, the number of branches that are created can quickly add up. Basic GitHub etiquette calls for you to delete merged branches or branches no longer required. Here’s how.
Delete a Branch Using GitHub’s Website (Remote Branches Only)
You can delete a branch using GitHub’s website. However, you’re only able to delete remote branches using this method—you can’t delete local branches from GitHub’s website.
To get started, visit the official GitHub website and log in to your account. Once logged in, select the repository that contains the branch you would like to delete from the left-hand pane.
Next, click “Branches” below the header menu.
A list of branches will appear. Locate the branch you’d like to delete and then click the red trash can to the right of it.
The branch is now deleted. To reflect this change in your local repository, change to the respective directory, checkout the main branch, and then run the git –pull command from the command line.
Delete a Local or Remote Branch From the Command Line
You can delete both local and remote branches using the command line. First, open the command line of your choice, change to the directory of your GitHub repository (cd
There are two different commands you can run to delete a local branch. If it’s already been merged, run:
Or, to force delete a branch regardless of its current status, run:
Just replace
The local branch is now deleted. If you’re wanting to delete a remote branch, you will run:
Replace
The remote branch is now deleted.
If you’re deleting branches in a GitHub repository that’s no longer active or needed, you don’t have to delete the branches one by one—you can delete the entire repository.
RELATED: How to Delete a GitHub Repository