Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

Git merge explained: merging branches

Merge is the operation that brings together work from multiple branches. Understand the different types of merges, conflicts, and how to resolve them with confidence.

merge
Most used command in teams
2
Main types of merge
90%
Of conflicts resolve in 5 min
50+
Investigations to practice
Key concept

What is git merge?

git merge combines the work of two branches into one. It's the fundamental operation of collaborative work with Git.

You create a branch

You work on your feature in a separate branch, without touching main.

You finish your work

Your changes are committed. Your branch is ready to be integrated.

You do the merge

You switch to main and merge your branch. The work is integrated.

The two types of merge

Simple

Fast-forward

When main has not received any new commits. Git simply moves the pointer forward. No merge commit, linear history.

Standard

Merge commit

When both branches have diverged. Git creates a special commit that combines changes from both sides.

Do not panic

Resolving a merge conflict

A conflict happens when Git cannot automatically decide which version to keep. It's not an error, it's a question.

1. Identify

git status shows you the conflicted files. Open them in your editor.

2. Resolve

Choose the version to keep, combine if necessary, and remove the conflict markers (<<<<<).

3. Confirm

git add then git commit to finalize the resolution.

Essential merge commands

git merge <branch>

Merge the specified branch into the current branch

git merge --no-ff <branch>

Force creating a merge commit (no fast-forward)

git merge --abort

Cancel a merge in progress (in case of conflict)

git mergetool

Open a visual tool to resolve conflicts

git log --merge

Show the commits causing the conflict

git diff

During a conflict, show the differences to resolve

Part of the Git Branching Workflow guide

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about git merge

Ready to master merge?

Conflicts are no longer scary once you have practiced. Practice merge in a safe environment with GitQuest.

Practice merge