How to Manage Branches in GitLab? Last Updated : 10 Oct, 2024 Summarize Comments Improve Suggest changes Share Like Article 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 More infoAdvertise with us Next Article How to Manage Branches in GitLab? X xenlon Follow Improve Article Tags : Web Technologies Git Similar Reads How to Rename Branch in Git? Renaming branches in Git is important for keeping your repository organized and understandable, especially when collaborating with others. Clear and descriptive branch names improve project management and help team members identify the purpose of each branch. Renaming branches also ensures consisten 1 min read How to Merge Two Branches in Git? Version control systems like Git provide powerful tools for managing code changes and collaboration among developers. One common task in Git is merging branches, which allows you to combine the changes made in one branch into another. In this article, we will explore the process of merging branches 4 min read How to Delete Branch in Gitlab? When working with Git, it's common to create branches to isolate changes and work on new features or fixes. However, once a branch has served its purpose, it's often necessary to delete it to keep your repository clean and organized. In this article, we'll see the process of deleting a Git branch us 2 min read How to List Remote Branches in Git? Git is a powerful version control system that allows developers to collaborate on projects, maintain code history, and manage multiple lines of development through branching. One common task when working with Git is to list all branches in a remote repository. This article will guide you through the 3 min read How To Fetch Remote Branches in Git ? Git provides a powerful version control system that allows developers to collaborate efficiently on projects. Over time, however, a repository can have local and remote branches. Local branches are created locally and only exist on local machines and the remote branches exist on the remote repositor 3 min read Like