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:
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:
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:
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:
Or,
$ git push origin –delete improved
Or,
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.
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.