Skip to main content

How to - git branch

When working together on a repository, it can be annoying to always use git merge. Branches offer the ability to temporarily diverge from the main codebase. The default branch is typically named "main" or "master". Everything merges back into the "main" branch eventually.

How to create a branch?

  1. To use branches, you must have an existing repository. If you haven't created one yet, follow this Guide.
  2. Next, clone your repository if you haven't done so already. Follow this Guide if you encounter any issues.
  3. Create the branch. There are multiple ways to do this:

Using GitLab in the Browser

Screenshot gitlab branch menu Screenshot gitlab branch createMenu Screenshot gitlab branch created

Using the Terminal

  1. Open the Terminal (Mac/Linux), GitBash, CMD, or PowerShell (Windows).
  2. Navigate to your repository directory.
  3. Run the following command: git checkout -B test-terminal If successful, you will see: "Switched to a new branch 'test-terminal'".

Directly in JetBrains Products

  1. Open your repository in a JetBrains product of your choice (e.g., IntelliJ).
  2. Open the Git pane (bottom left).
  3. Right-click on the Main branch.
  4. Click on "New Branch from 'main'...".
  5. Create the branch.

Screenshot JetBrains branch menu Screenshot JetBrains branch popup