How to Delete Remote Branch in Git

29/12/2020
Git
In this article, I am going to show you how to delete or remove a remote Git branch. I will use a GitHub repository as a remote Git repository for the demonstration. But, you can use any other remote Git repository hosted on other platforms such as BitBucket, GitLab etc as well.

Cloning the Remote Git Repository:

In this section, I am going to show you how to clone a remote Git repository on your local computer for deleting or removing a branch from the remote Git repository.

I will use one of my GitHub repository (https://github.com/dev-shovon/hello-c) for the demonstration.

To clone your desired GitHub repository on your local computer, run the following command:

$ git clone https://github.com/dev-shovon/hello-c

The remote Git repository should be cloned.

A new directory should be created as you can see in the screenshot below.

Now, navigate to the newly created directory with the following command:

$ cd hello-c/

Listing Remote Branches:

Before you delete or remove a remote Git branch, it is important to know what remote branches are available. You can get a list of all the remote Git branches from the command line very easily.

To list all the Git remote branches, run the following command:

$ git branch –remotes

As you can see, all the remote branches are listed. Let’s remove the origin/improved branch. Here, origin is the name of the remote repository and improved is the name of the remote branch.

Removing Remote Repository:

To remove the improved branch from the origin repository, you can run one of the following commands:

$ git push origin -d improved
Or,
$ git push origin –delete improved

Or,

$ git push origin :improved

NOTE: A colon (:) before the branch name has the same effect as the -d or –delete option of git push.

You will be prompted for the username and password of your remote Git repository. For GitHub, it is the login details of your GitHub account. Once you provide the login details, the remote Git branch (improved in this case) should be removed.

As you can see, the remote branch origin/improved is no longer listed.

$ git branch –remotes

As you can see, the branch improved is not listed on my GitHub repository as well. So, it is removed for good.

So, that’s how you delete or remove a remote branch in Git. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Install Git on Ubuntu

Git is a distributed version control system. It is used to track changes in source codes during software development. It...
29/12/2020

How to Use git blame

git blame is a very good tracking command for Git. git blame shows the author information of each line of the project’s...
29/12/2020

Git Branch Basics

Basics of Git Branching The ability to easily branch is one of the best features of Git. Creating branches in other version...
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?
27/05/2024