Git Commands: Managing Branches

One of Git’s most impressive features is its powerful branching capabilities. Though competing tools — especially centralized ones — make a big deal out of branching and merging, these are typically easy operations in Git. However, working with an online repository host, such as GitLab, adds another layer of complexity. Since now they have to deal not only with their local branches but also with remote ones, many users often get confused and frustrated at this point. In this post, we’ll show you the main Git commands you must be aware of so you can manage your branches in an easy and efficient way.

Creating and Switching To Branches in GitLab

Then, to switch to your new branch, you can use both the checkout and the switch commands. So, the two following alternatives achieve the same result:

The checkout command is older and does a lot of things. The switch command, on the other hand, is newer. It was introduced as an experimental command in version 2.23 and is dedicated only to switching to branches. When you create a branch, most of the time you’ll also want to switch to it, so there are ways to do the two things in one go. The following example creates a new branch called “test” and immediately switches to it, using two possible alternatives:

Git Merge: Integrating Changes From Different Branches

In this case, only one of the two sides diverged. In such a scenario, the merge operation is simpler and called a fast-forward merge.

Working With Remote Branches

Cloning a Repository

Adding a Remote

Checking Out Remote Branches

Git and GitLab Branch Management: Where to Go From Here?

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cprime

An Alten Company, Cprime is a global consulting firm helping transforming businesses get in sync.