Merging branches in Git is useful for combining changes from one branch into another, and for preserving history.
In this example, we’re going to merge a Git branch with master. Let’s say you have a master branch with changes. You then branch off into a feature branch and make additional changes.
To merge the feature branch, you will want to first checkout your master branch with
git checkout master
GitTip: Need help? See the step-by-step process of how to checkout a Git branch locally and how to checkout a remote Git branch.
Then use the command
git merge feature
You will then merge changes from the feature branch over to master, adding all changes from the feature branch to master. This gives you an accurate representation of the history, in addition to getting all the changes combined onto master.
How do you merge a Git branch in GitKraken?
To make the process even easier, you can use a Git client, like GitKraken, to visualize the branching process in Git.
Follow along with an example using the GitKraken Git GUI
In this example, we will again merge a Git branch with master. You have a master 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 master branch from the central graph, or right-click the branch and select Checkout master.
How do you merge a Git branch with master in GitKraken?
After you checkout the master branch, you will drag-and-drop your feature branch onto the master branch in the central graph, or right-click the feature branch, and select Merge feature into master 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 Git GUI.