Skip to main content

Git Merge Conflict Simulator

Resolve Git merge conflicts in a browser lab. Read the conflict markers and the three index stages, edit the file to what it should be, take a side with --ours or --theirs, see why they swap during a rebase, back out with git merge --abort, and catch a clean merge that breaks the build.

Category: DevOps

What You Will Learn

  • Read Git conflict markers: <<<<<<< HEAD, ======= and >>>>>>>
  • Inspect the base, ours and theirs versions with git show :1: :2: :3:
  • Resolve a conflict by editing the file, then git add and git commit
  • Use git checkout --ours and --theirs to take a whole side, for example for a binary file
  • Understand why ours and theirs swap during a git rebase
  • Back out of a bad merge with git merge --abort
  • Catch a semantic conflict: a clean merge that breaks the tests

Topics covered: git, merge-conflict, version-control, rebase, terminal, devops, educational, interactive

// simulator

Git Merge Conflict Simulator

Resolve Git merge conflicts in a browser lab. Read the conflict markers and the three index stages, edit the file to what it should be, take a side with --ours or --theirs, see why they swap during a rebase, back out with git merge --abort, and catch a clean merge that breaks the build.

Supported byBecome a sponsor
SvixAtomsizedDigitalOceanDevDojoSMTPfastQuizAPI

// CONFLICT (content)

Git Merge Conflict Simulator

Each lesson opens on a real-looking conflict. Read the markers, resolve the file, take a side, survive a rebase, back out with --abort, and catch the merge that Git called clean.

Progress0/27

Branch

main

Unmerged

1

Staged

0

Lessons
Lesson 1 / 6
Step 1 / 5

The merge stopped. Ask Git what state the repository is in.

1service: api
2<<<<<<< HEADours: main (HEAD)
3timeout: 45
4=======
5timeout: 60
6>>>>>>> feature/retrytheirs: feature/retry
7retries: 3
~/repo
main|MERGING
$ git merge feature/retry
Auto-merging config.yaml CONFLICT (content): Merge conflict in config.yaml Automatic merge failed; fix conflicts and then commit the result.
$
Repository

Merging feature/retry into main

HEAD
main @ e41c9d2
MERGE_HEAD
feature/retry @ 9b27c40
  • README.mdclean
  • config.yamlboth modified
Index stages: config.yaml

:1: base (common ancestor)

service: api
timeout: 30
retries: 3

:2: ours: main (HEAD)

service: api
timeout: 45
retries: 3

:3: theirs: feature/retry

service: api
timeout: 60
retries: 3
Ours and theirs

During a merge (now)

--ours = the branch you are on

--theirs = the branch you are merging in

During a rebase

--ours = the rebased result so far: the branch you rebase onto, plus your commits already replayed

--theirs = your commit being replayed

About this merge conflict simulator

What you'll learn

  • What the conflict markers delimit, and which side is which
  • The index stages Git keeps for an unmerged file: up to three, base, ours and theirs
  • That resolving means writing the file you want, not picking a side
  • When taking a whole side is right, as with a binary file
  • Why --ours and --theirs swap meaning during a rebase
  • How to back out of a merge with git merge --abort
  • Why a clean merge can still break the build

Key commands covered

  • Inspect: git status, git diff, git show :1:/:2:/:3:<file>, git log --merge
  • Resolve: edit the file, git add, git commit
  • Take a side: git checkout --ours / --theirs, git checkout -m to start over
  • Rebase: git rebase --continue, --abort
  • Escape: git merge --abort
During a--ours / HEAD--theirs
mergethe branch you are onthe branch you are merging in
rebasethe rebased result so far: the branch you rebase onto, plus your commits already replayedthe commit being replayed

The conflict Git cannot see

Git merges text. When two branches change different lines that depend on each other, the merge can be textually clean while the combined code is broken. Run your tests on the merge result, not only on each branch: CI on merge commits, or a merge queue that tests the combined code before it lands.

Learn by breaking things

This simulator does not run real Git. It models each repository in the browser, with the output real Git prints, so you can make the mistakes here first. For the model behind branches and commits, try the Git Concepts Simulator, and read why Git is best learned by breaking something and getting it back.

Try next

Sponsored
Carbon Ads
$ cd /games
// share