GIT · Branches · 10 min

Keep both sides of a merge

Resolve a conflict by understanding what each branch changed.

Not completed

Your task

Finish the merge already in progress. config.json must contain region staging and retries 3. Keep a merge commit with both parents and a clean working tree.

What you’re aiming for

  • config.json is valid JSON with region staging and retries 3.
  • The merge commit preserves both branch parents.
  • No conflict or uncommitted change remains.

1. Prepare your practice folder

Use Git 2.28 or newer. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.

Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.

NEW PRACTICE FOLDER
mkdir opsrung-git-resolve-conflict && cd opsrung-git-resolve-conflict

Run these setup commands in that folder:

SETUP — RUN ONCE
git init --initial-branch=main
git config --local user.name 'Practice Learner'
git config --local user.email 'practice@example.invalid'
printf '%s\n' '{"region":"local","retries":1}' > config.json
git add config.json
git commit -m 'Initial configuration'
git switch -c feature/retries
printf '%s\n' '{"region":"local","retries":3}' > config.json
git add config.json
git commit -m 'Increase retries'
git switch main
printf '%s\n' '{"region":"staging","retries":1}' > config.json
git add config.json
git commit -m 'Use staging region'
git merge feature/retries
Only if your personal Git settings interfere

You can normally skip this. If a commit asks for a signing key, runs a custom hook, or changes line endings unexpectedly, these repository-local overrides keep this disposable exercise independent of those settings.

OPTIONAL REPOSITORY OVERRIDES
git config --local commit.gpgsign false
git config --local core.autocrlf false
git config --local core.hooksPath .git/practice-no-hooks

Retry the failed command afterward. These settings apply only inside this practice repository.

A merge conflict is expected. The last command reports a conflict and leaves the merge unfinished. That is the starting point for your task.

2. Try the task

Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.

Hint 1

git status identifies the conflicted file. Open it in your editor and inspect the markers.

Hint 2

Choosing only ours loses the retry change; choosing only theirs loses the region change.

Hint 3

Replace the markers with the combined JSON, stage config.json, and commit the merge.

3. Review your result

Use these commands to look at your result and compare it with the goals. The website does not run or verify them.

REVIEW IN YOUR TERMINAL
cat config.json
git log -1 --format=%P
git status

What you should see

  • config.json is valid JSON with region set to staging and retries set to 3.
  • git log -1 --format=%P prints two commit hashes separated by a space.
  • git status reports a clean working tree and no merge in progress.

If your result differs: A conflict during setup is expected. Remove the conflict markers, keep both intended changes, and finish the merge commit.

Compare with one possible solution

Edit config.json to contain:

{"region":"staging","retries":3}
ONE POSSIBLE SOLUTION
git add -- config.json
git commit -m "Combine region and retry settings"

Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.

Finished this exercise?

You decide when you’re done. Your choice is saved in this browser, and you can change it later.