Bird
Raised Fist0
Gitdevops~20 mins

git merge command - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Git Merge Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a fast-forward merge
You have a branch feature that is ahead of main with new commits. You run git checkout main and then git merge feature. What is the output?
Git
git checkout main
git merge feature
A
Updating abc1234..def5678
Fast-forward
B
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
CAlready up to date.
Derror: You have unmerged files.
Attempts:
2 left
💡 Hint
Think about what happens when the target branch has no new commits since the source branch diverged.
💻 Command Output
intermediate
2:00remaining
Result of merging with conflicts
You try to merge branch feature into main, but both branches changed the same lines in a file. What output does git merge feature produce?
Git
git checkout main
git merge feature
A
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
BAlready up to date.
Cerror: Your local changes to the following files would be overwritten by merge
DFast-forward
Attempts:
2 left
💡 Hint
Conflicts happen when the same lines are changed differently in both branches.
Configuration
advanced
2:00remaining
Configuring merge strategy for a branch
You want to always use the 'ours' merge strategy when merging the experimental branch into main. Which git config command sets this behavior?
Agit config branch.main.merge '--strategy=ours'
Bgit config branch.experimental.mergeoptions '--strategy=ours'
Cgit config branch.experimental.merge '--strategy=ours'
Dgit config branch.main.mergeoptions '--strategy=ours'
Attempts:
2 left
💡 Hint
The config key for merge options is under the branch name you want to configure.
Troubleshoot
advanced
2:00remaining
Cause of 'fatal: refusing to merge unrelated histories' error
You run git merge feature but get the error fatal: refusing to merge unrelated histories. What is the most likely cause?
AThere are uncommitted changes in the working directory.
BThe branches come from repositories with no common commit history.
CThe feature branch has merge conflicts.
DThe main branch is already up to date.
Attempts:
2 left
💡 Hint
Think about what it means for histories to be unrelated.
🔀 Workflow
expert
3:00remaining
Correct sequence to merge a remote branch with conflict resolution
You want to merge the remote branch origin/feature into your local main branch and resolve conflicts if any. What is the correct order of commands?
A1,3,2,4
B1,2,3,4
C2,1,3,4
D2,3,1,4
Attempts:
2 left
💡 Hint
You must update your remote tracking branches before merging.

Practice

(1/5)
1. What does the git merge command do in Git?
easy
A. It combines changes from one branch into the current branch.
B. It deletes a branch permanently.
C. It creates a new branch from the current branch.
D. It shows the commit history of the current branch.

Solution

  1. Step 1: Understand the purpose of git merge

    The git merge command is used to combine changes from one branch into another branch.
  2. Step 2: Identify the correct description

    Among the options, only It combines changes from one branch into the current branch. correctly describes merging changes into the current branch.
  3. Final Answer:

    It combines changes from one branch into the current branch. -> Option A
  4. Quick Check:

    git merge = combine branches [OK]
Hint: Merge means combine changes into current branch [OK]
Common Mistakes:
  • Confusing merge with branch deletion
  • Thinking merge creates a new branch
  • Mixing merge with viewing history
2. Which of the following is the correct syntax to merge branch feature into the current branch?
easy
A. git merge --create feature
B. git merge -b feature
C. git merge feature
D. git merge --delete feature

Solution

  1. Step 1: Recall the basic merge syntax

    The correct syntax to merge a branch is git merge branch_name.
  2. Step 2: Match the syntax with options

    git merge feature matches the correct syntax. Options B, C, and D use invalid flags or commands.
  3. Final Answer:

    git merge feature -> Option C
  4. Quick Check:

    git merge + branch name = correct syntax [OK]
Hint: Use 'git merge branch_name' to merge branches [OK]
Common Mistakes:
  • Adding incorrect flags like -b or --create
  • Confusing merge with branch creation or deletion
  • Using merge without specifying branch name
3. Given the following commands run in order:
git checkout main
git merge feature

What happens if the feature branch has commits not in main?
medium
A. The main branch is reset to feature branch state.
B. The feature branch is deleted automatically.
C. Git throws an error and stops the merge.
D. The commits from feature are added to main.

Solution

  1. Step 1: Understand merge behavior with new commits

    When merging a branch with new commits, Git combines those commits into the current branch.
  2. Step 2: Analyze the options

    The commits from feature are added to main correctly describes this behavior. Options B, C, and D describe incorrect or unrelated behaviors.
  3. Final Answer:

    The commits from feature are added to main. -> Option D
  4. Quick Check:

    Merge adds commits [OK]
Hint: Merge adds commits, does not delete branches [OK]
Common Mistakes:
  • Thinking merge deletes branches
  • Expecting merge to reset branches
  • Assuming merge always fails with new commits
4. You run git merge feature but Git reports a conflict. What should you do next?
medium
A. Restart Git to clear the conflict.
B. Manually resolve the conflicts in files, then run git add and git commit.
C. Run git merge --force to ignore conflicts.
D. Delete the feature branch and try merging again.

Solution

  1. Step 1: Understand merge conflicts

    When Git reports conflicts, it means changes clash and need manual fixing.
  2. Step 2: Resolve conflicts properly

    You must edit conflicted files to fix issues, then stage and commit the changes to complete the merge.
  3. Final Answer:

    Manually resolve the conflicts in files, then run git add and git commit. -> Option B
  4. Quick Check:

    Fix conflicts manually, then add and commit [OK]
Hint: Fix conflicts manually, then add and commit [OK]
Common Mistakes:
  • Trying to force merge ignoring conflicts
  • Deleting branches to fix conflicts
  • Restarting Git expecting conflicts to clear
5. You want to merge branch feature into main but keep main's changes in case of conflict (favor main). Which command helps achieve this?
hard
A. git merge -X ours feature
B. git merge --no-ff feature
C. git merge -s recursive feature
D. git merge --abort feature

Solution

  1. Step 1: Understand merge strategies

    The -X ours option tells Git to favor the current branch's changes during conflicts.
  2. Step 2: Match the option to the goal

    git merge -X ours feature uses -X ours to keep main's changes if conflicts occur. Other options do not achieve this.
  3. Final Answer:

    git merge -X ours feature -> Option A
  4. Quick Check:

    Use -X ours to favor current branch on conflicts [OK]
Hint: Use 'git merge -X ours' to keep current branch changes [OK]
Common Mistakes:
  • Confusing -X ours with --no-ff
  • Using --abort to fix conflicts
  • Not specifying strategy option