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.