Like other Remote host servers, GitLab also has the concept of branches for working with different features and issue fixes while isolating the new code from the main codebase. Users can create multiple branches for each development module. By default, the repositories have a βmainβ branch for the codebase. However, users can make new branches to work on several features. Sometimes users are required to delete the branches that can be unprotected. For that purpose, they can use Git’s different commands.
This blog will describe the method of removing a GitLab branch from Git.
How to Remove a GitLab Branch from Git?
To remove the GitLab branch from Git locally and remotely, check out the provided steps:
- Navigate to the Git root directory.
- List all existing remote branches using the βgit branch -rβ command.
- Select the target branch and execute the βgit push <remote-name> –delete <remote-branch>β command.
Step 1: Move to Git Root Directory
Initially, execute the βcdβ command along with the Git root path and move to it:
Step 2: List All Remote Branch
Then, display all GitLab remote branches by using the βgit branchβ command and β-rβ option that indicates the remote:
As you can see, all the remote branches have been listed and we have selected the βorigin/betaβ branch that we want to delete:
Step 3: Delete Remote Branch
To remove a remote branch, execute the following command:
Here:
- βoriginβ is our remote URL name.
- β–deleteβ option is used for deleting purposes.
- βdevβ is the target branch.
According to the below-given output, the remote branch has been removed:
Step 4: Verification
Lastly, use the provided command for verifying whether the specified remote branch has been removed or not:
Thatβs it! We have described the way for removing the GitLab branch from Git.
Conclusion
To delete the GitLab branch from Git, first, navigate to the Git root directory and list all existing remote branches by running the βgit branch -rβ command. Then, choose one of them and run the βgit push <remote-name> –delete <remote-branch>β command. This tutorial described removing a GitLab branch from Git.