How to Manage Branches in GitLab? Last Updated : 10 Oct, 2024 Comments Improve Suggest changes 1 Likes Like Report GitLab is a web-based platform (like GitHub) that provides services related to the version control system of a project. Branching is one such concept of the version control system. Note: Make sure you have created a GitLab account and a repository.These are the following approaches to Manage branches in GitLab:Table of ContentUsing GUI method (GitLab website)Using Git (command line method)Using the GUI method (GitLab website) Open your repository and click on the branches tab as shown in the image below. Here we have created a sample repository using the default NodeJS template provided by GitLab. Create a new branch from the master branch of our repository.Creating a new branchThe test branch will be identical to our master branch. Add some changes to server.js file of test branch. Here we have changed the message from "Hello, World" to "Hello from GeeksForGeeks!". Commit the changes before exiting.Added changes to server.js of test branchNow we can compare the differences between branches by click on compare button. Select the source branch as test and target branch as master. Note that you can only find the compare button in any branch you have created expect the master branch. We can also delete the branch we have created through the branches tab. However, we will try to merge this test branch with our master branch first. We can also see the compare button here in the drop-down menu along with the delete button.Option to delete branch In order to merge the branch, go to the compare tab (as shown in 3rd step). There you can find the option to create merge requests. There is also a tick-box to delete the test branch if the merge request is accepted.You can see the merge requests in the merge requests tab. Check the changes before accepting it. You can also select whether the branch which is to be merged should be deleted or kept if the request is accepted.After merging the branches, the changes made to test branch will be followed to the master branch automatically. If we want to roll back the changes made due to merging the branches, we can create a new merge request to revert back the changes made earlier by the particular merge action.Using Git (command line method) In order to open the repository in your local machine, you must clone it first. Make sure to change the directories accordingly where you want to store the project. Find the URL of your repository in the homepage. Clone the repository using the command:git clone <url> In order to create a branch, enter into your project folder and type the following command in your terminal and press enter:git branch <branch-name>For making changes into the server.js file of test branch, we must first switch to the test branch, change the branch by using the command:git checkout <branch-name>Make the changes to server.js file using the command of your IDE or text editor and the file name. Here we are using simple notepad which comes pre-installed in windows 10.notepad server.jsPush the changes (creating a new branch and making changes to server.js of test branch) using the commands:git add .git commit -m "commit-message"git push -u origin <branch-name>Pushing changes to remote repositoryThe remote repository has been updated with new branch named test having a slightly different server.js file. In order to merge master and test branches run the commands which will navigate to target branch (master), merge the branches and push the changes:If you want to delete the new branch after it is merged, then you can use the following command while pushing the changes to remote repository:git push origin --delete <branch-name> Comment X xenlon Follow 1 Improve X xenlon Follow 1 Improve Article Tags : Web Technologies Git Explore Git Tutorial 6 min read Git IntroductionGit Introduction 5 min read Introduction to Github 5 min read An Ultimate Guide to Git and Github 12 min read What is Git? 6 min read What Is Gitlab? Complete Guide 4 min read Git Bash 9 min read Git Installation and SetupHow to Install GIT on Linux 4 min read How to Install Git on Windows Command Line? 3 min read Git - Environment Setup 2 min read How To Install Git on Ubuntu 20.04 3 min read How to Install Git in VS Code? 2 min read How to Install Git on Cygwin? 2 min read How to Install and Use GIT in Android Studio? 4 min read How to Setup Git Using Git Config? 3 min read Git- Setting up a Repository 3 min read How to install Git on Redhat Linux 9? 4 min read How to Install Git on Termux? 2 min read How to Install Git in FreeNAS? 4 min read How to Install Git on Raspberry Pi? 2 min read How to Install GIT on VMWare? 2 min read How to Install Git in Cpanel Server? 3 min read How To Install Git on AWS? 2 min read How to Setup Git Server on Ubuntu? 6 min read How to Install Git on Windows Subsystem for Linux? 2 min read All Git CommandsBasic Git Commands with Examples 4 min read 50+ Essential Git Commands for Beginners and Developers 7 min read Top 12 Git Commands for Every Developer 9 min read Essential Git Commands 3 min read Useful Git Commands and Basic Concepts 5 min read All Git Commands You Should Know 8 min read Simple and Concise Git Commands That Every Software Developer Should know 4 min read Most Used Git CommandsGit Init 3 min read Git Pull 4 min read Git Push 4 min read Git Clone 5 min read Git Rebase 8 min read How To Fetch Remote Branches in Git ? 3 min read Git Status 2 min read Git Add 2 min read Git Commit 2 min read Git Reset 3 min read Git BranchBranching Strategies in Git 8 min read Introduction to Git Branch 4 min read How To Create Branch In Git? 2 min read How to Create a Branch In Git from Another Branch? 3 min read How to Create a New Branch in Git and Push the Code? 8 min read How To Publish A New Branch In Git? 4 min read How to Create Git Branch With Current Changes? 1 min read Create a Git Branch From Another Branch 4 min read How to Create a New Branch in Git? 4 min read How to Create Branch From a Previous Commit Using Git? 2 min read How To Visualizing Branch Topology in Git? 3 min read How to Check Branch in Git? 2 min read How to Clone a Branch in Git? 3 min read How to Fetch All Git Branches? 2 min read Git MergeGit - Merge 5 min read Git Checkout And Merge 5 min read How to Merge Two Branches in Git? 4 min read How to Merge a Git Branch into Master? 3 min read How to Replace Master Branch with Another Branch in GIT? 2 min read Git Merge and Merge Conflict 3 min read Git Tools and IntegrationWorking on Git for GUI 4 min read How Git Version Control Works? 11 min read How To Write CI/CD Pipeline Using GitLab? 8 min read Git and DevOps: Integrating Version Control with CI/CD Pipelines 11 min read How To Create A Basic CI Workflow Using GitHub Actions? 5 min read How To Set Up Continuous Integration With Git and Jenkins? 4 min read How to Set Up a CI Pipeline for Ktor Using GitHub Actions? 6 min read Introduction to GitHub Actions 4 min read Basic CI Workflow For Android using GitHub Actions 2 min read Integrating Jenkins With Popular GitHub 8 min read Managing Git Repositories with GitLab 3 min read Git Remote RepositoriesUnderstanding Git Repository 4 min read Git- Setting up a Repository 3 min read Creating Repository in GitHub 3 min read Working With Git Repositories 7 min read Collaborating with GitGit - Fork 4 min read Difference Between fork and clone in GitHub 3 min read How to Fork a GitHub Repository? 3 min read Sync Your Fork With Master in GitHub 3 min read How to Update or Sync a Forked Repository on GitHub? 2 min read Like