NEW COURSE • 100% FREE

Foundations Of AI For Software Development

Enroll To Get Started →

DIWALI SALE

Get 60-70% OFF GitKraken Pro! Ends In

Days
Hours
Minutes
Seconds
DEEPAVALI SALE

Get 60-70% OFF GitKraken Pro! Ends In

Days
Hours
Minutes
Seconds
OFERTA DÍA DE MUERTOSAHORRA HASTA 70%Oferta Por Tiempo LimitadoComprar ahora
🪔 DIWALI SALE Claim 60-70% Off →
🪔 DEEPAVALI SALE Claim 60-70% Off →

How do you merge branches in Git?

To merge a branch, check out the branch you want to merge into, then run git merge with the name of the branch you’re bringing in:

git switch main
git pull
git merge feature/login

Git combines the commits from feature/login into main. If both branches changed the same lines, Git stops and asks you to resolve a merge conflict.

H2: Fast-forward vs. merge commit

If main hasn’t changed since you created your branch, Git does a fast-forward merge. It moves main forward to your latest commit without creating a new commit. If both branches have new commits, Git creates a merge commit that ties the two histories together.

To always create a merge commit, so the branch stays visible in your history, run:

 
git merge --no-ff feature/login

How do you merge a Git branch in GitKraken?

To make the process even easier, you can use GitKraken Desktop, to visualize the branching process in Git.

Follow along with an example using GitKraken Desktop

In this example, we will again merge a Git branch with main. You have a main branch with changes, but you have branched off into a feature branch to make additional changes.

You will start by checking out a branch. To do this in GitKraken, simply double-click the main branch from the central graph, or right-click the branch and select Checkout main.

How do you merge a Git branch with main in GitKraken?

After you checkout the main branch, you will drag-and-drop your feature branch onto the mainbranch in the central graph, or right-click the feature branch, and select Merge feature into main from the context menu.

Resolving a Merge Conflict in GitKraken

In Git, a merge conflict can occur if there are competing changes made to the same file, or line of a file, between the branches.

In the command line, resolving merge conflicts can be complicated and stressful. By comparison, the GitKraken merge conflict editor clearly visualizes the conflicting files for you so you can see where the variances in your code exist.

When using GitKraken’s merge tool, each conflict section will have an accompanying checkbox. Checking a section’s box will add it to the output section at the bottom. This allows you to see your available options in context to decide how best to proceed.

Main vs Master Branches in Git

The term “master” is outdated; we recommend using “main” instead when possible.

Setting your default branch name in GitKraken is quick and easy. You can do this when you initialize a new Git repository in GitKraken, or from the Preferences menu.

Making merging branching in Git easier and more intuitive, and get more confidence in your workflow, with the power of the GitKraken Desktop.

Additional Resources

Table of Contents

Visual Studio Code is required to install GitLens.

Don’t have Visual Studio Code? Get it now.

Team Collaboration Services

Secure cloud-backed services that span across all products in the DevEx platform to keep your workflows connected across projects, repos, and team members
Launchpad – All your PRs, issues, & tasks in one spot to kick off a focused, unblocked day. Code Suggest – Real code suggestions anywhere in your project, as simple as in Google Docs. Cloud Patches – Speed up PR reviews by enabling early collaboration on work-in-progress. Workspaces – Group & sync repos to simplify multi-repo actions, & get new devs coding faster. DORA Insights – Data-driven code insights to track & improve development velocity. Security & Admin – Easily set up SSO, manage access, & streamline IdP integrations.
winget install gitkraken.cli