Open In App

How to Delete Branch in Github?

Last Updated : 07 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In Git repositories, branches are important for organizing and managing code changes, but over time, unused or outdated branches can clutter the repository. Deleting these branches helps maintain a clean and manageable codebase. In this article, we'll explore the process of deleting branches in GitHub, both through the web interface and using Git commands.

Deleting Branches via GitHub

The easiest way to delete a branch is using GitHub's web interface. Follow these steps to delete a branch using the GitHub web interface:

Step 1: Begin by logging in to your GitHub account.

Search for GitHub and login to your GitHub account.

Step 2: Navigate to the repository containing the branch you want to delete

You can navigate by either searching for it in the search bar at the top of the GitHub interface or by accessing it directly if it's listed on your dashboard.

repo_gfg
Repository

Step 3: Click on the "Branches" tab within the repository

repo_gfg
Github branches of the repository

Step 4: Locate the specific branch you wish to remove from the list displayed:

Click the View all branches option, you will see a list of branches. We will select the test_gfg branch as we want to delete it.

repo_gfg
List of branches

Step 5: Next to the branch name, you'll see a small trash can icon. Click on it.

Click the small trash icon, visible infront of the branch name that you want to delete. The branch will be deleted.

Deleting Branches via Command Line (Git)

If you're familiar with the command line interface, Git offers efficient options for deleting branches. Here's how you can do it:

Step 1: Open your terminal and navigate to the local repository directory

Use the cd command to navigate to the directory where your local repository is located.

repo_gfg
Local repository directory

Step 2: Delete a remote branch

Our test_gfg is a remote branch and to delete a remote branch, use the command:

git push origin --delete branch_name
repo_gfg
test_gfg remote branch deleted


By following these steps we can successfully deleted the branch.


Next Article
Article Tags :

Similar Reads