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.
GitKraken MCP
GitKraken Insights