Cyberithub

How to Delete a Remote Source Repositories Branch from Cloud Shell

Advertisements

In this article, we will discuss on how to delete a Remote Source Repositories Branch from Cloud Shell. Sometimes it may happen that you are done with the work on some of the branches and does not need it anymore so you want to delete it from Source Repositories. You can easily delete the remote branch using git command either from local git command or using git from Cloud Shell. Here we will see the steps to delete a remote Source Repositories branch from Cloud Shell.

How to Delete a Remote Source Repositories Branch from Cloud Shell

Delete a Remote Source Repositories Branch from Cloud Shell

Also Read: Create a Repository Using Google Source Repositories(GSR) in 5 Simple Steps

Step 1: Prerequisites

a) You should have a valid Google Email ID and Password.

b) You should have all the permission to delete a branch of Specified Source Repositories.

c) You need to activate the Cloud Shell.

d) git command should be available from Cloud Shell.

Step 2: Clone Your Remote Source Repository

In the first step, you need to first clone the remote source repository from Cloud Shell using below git clone command. Below given URL path is taken from my project Source Repositories so it could be different for your remote source repository. More on Git Command.

Project Name: sample-project-308612

Repo Name: sample-project-repo

cyberithub@cloudshell:~ (sample-project-308612)$ git clone https://source.developers.google.com/p/sample-project-308612/r/sample-project-repo
Cloning into 'sample-project-repo'...
remote: Total 5 (delta 1), reused 5 (delta 1)
Unpacking objects: 100% (5/5), done.

Step 3: Go to Project

Once cloning is completed, you can go to the project by using cd sample-project-repo/ command and then run git branch -a command to check all remote branches.

cyberithub@cloudshell:~ (sample-project-308612)$ cd sample-project-repo/

NOTE:

Please note that if you run only git branch command instead of git branch -a command then it will only show the current branch you are in and not the remote branches.
cyberithub@cloudshell:~/sample-project-repo (sample-project-308612)$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/master

Step 4: Delete Remote Branch

Now to delete the remote branch dev, you need to use git push origin --delete dev command as shown below. This command will delete the remote dev branch from sample-project-repo Repository.

cyberithub@cloudshell:~/sample-project-repo (sample-project-308612)$ git push origin --delete dev
To https://source.developers.google.com/p/sample-project-308612/r/sample-project-repo
- [deleted] dev

NOTE:

Please note that before deleting a branch you need to come out of that branch. Star(*) mark shows your current branch. So never try to delete a branch with * mark. Please be careful while deleting a branch as deleting incorrectly might cause irreparable losses.

After successful deletion, if you again run git branch -a command then you can see that dev branch is not present now. Only local master branch and remote master branch is available.

cyberithub@cloudshell:~/sample-project-repo (sample-project-308612)$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master

Similarly, you can also delete the remote master branch by using git push origin --delete master command as shown below.

cyberithub@cloudshell:~/sample-project-repo (sample-project-308612)$ git push origin --delete master
To https://source.developers.google.com/p/sample-project-308612/r/sample-project-repo
- [deleted] master

Again run git branch -a command to confirm the deletion. It shows that remote source repository master branch is deleted now. Similarly you can do the same activity for other unused remote branches. Hope it helps!!!

cyberithub@cloudshell:~/sample-project-repo (sample-project-308612)$ git branch -a
warning: ignoring broken ref refs/remotes/origin/HEAD
* master

Leave a Comment