How to remove a git branch in remote ?

Javascript Jeep🚙💨
3 min readApr 16, 2023

--

In this post we will learn about how to remove an branch from remote.

Photo by Yancy Min on Unsplash

Introduction

Git is a powerful version control system that allows developers to collaborate on projects and manage their codebase efficiently. One of the most useful features of Git is the ability to create and manage branches, which allows developers to work on different features or versions of their code simultaneously. However, as projects evolve, it’s essential to remove branches that are no longer needed to maintain a clean and organized repository. In this blog post, we’ll walk you through the process of removing a Git branch in remote.

Before we start, let’s clarify some Git terminology. The term “remote” refers to a repository hosted on a remote server, such as GitHub, GitLab, or Bitbucket, where multiple developers can collaborate on a project. On the other hand, “local” refers to a repository on your local machine, where you make changes to your code and push them to the remote repository.

Step 1: Check the list of Git branches in remote

To remove a Git branch in remote, you first need to know the name of the branch you want to delete. To do this, execute the following command in your terminal:

git branch -r

The above command will list all the remote branches of your repository. You should see something like this:

origin/HEAD -> origin/master
origin/develop
origin/feature-1
origin/master

In this example, we have four remote branches: HEAD, develop, feature-1, and master.

Step 2: Delete the Git branch in remote

Once you have identified the branch you want to delete, you can use the following command to remove it from the remote repository:

git push <remote_name> --delete <branch_name>

Replace <remote_name> with the name of your remote repository, such as origin, upstream, or any other custom name you may have set up. The <branch_name> denotes the name of the branch you want to delete.

For example, to delete the remote branch feature-1, you would run the following command:

git push origin --delete feature-1

The above command will remove the branch from the remote repository.

Step 3: Confirm the Git branch has been deleted

To confirm that the Git branch has been deleted from the remote repository, you can run the following command:

git branch -r

This command will list all the remote branches in your repository. If the branch you deleted is no longer listed, then it has been successfully removed from the remote repository.

Conclusion:

Removing a Git branch in remote is a simple process that can help you keep your repository clean and organized. By following the steps outlined in this blog post, you can easily delete any branch that is no longer needed. Always remember to confirm that the branch has been deleted by checking the list of remote branches. Happy coding!

--

--