Bird
Raised Fist0
Gitdevops~20 mins

Why merging combines work in Git - Challenge Your Understanding

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
🎖️
Master of Merging
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why does git merge combine work?

Imagine two friends writing a story separately on different pages. When they put their pages together, why does git merge combine their work?

ABecause it creates a new snapshot that includes changes from both friends' pages.
BBecause it deletes one friend's work and keeps only the other's.
CBecause it copies one friend's page over the other without changes.
DBecause it ignores all changes and keeps the original story only.
Attempts:
2 left
💡 Hint

Think about how git keeps track of changes from different sources.

💻 Command Output
intermediate
2:00remaining
Output of git merge with no conflicts

What is the output of the command git merge feature when the feature branch has new commits that do not conflict with the current branch?

Git
git merge feature
A
Updating abc1234..def5678
Fast-forward
BAutomatic merge failed; fix conflicts and then commit the result.
Cerror: You have not concluded your merge (MERGE_HEAD exists).
DAlready up to date.
Attempts:
2 left
💡 Hint

Think about what happens when the merge can be done without conflicts.

Troubleshoot
advanced
3:00remaining
Resolving merge conflicts

You run git merge feature and get a conflict message. What is the correct next step to combine work?

Git
git merge feature
ADelete the conflicting files and run <code>git commit</code>.
BEdit the conflicting files to fix conflicts, then run <code>git add</code> and <code>git commit</code>.
CRun <code>git push</code> immediately to overwrite remote.
DRun <code>git merge --abort</code> to cancel and lose all changes.
Attempts:
2 left
💡 Hint

Conflicts need manual fixing before completing the merge.

🔀 Workflow
advanced
3:00remaining
Merging multiple branches workflow

You have branches dev, feature1, and feature2. To combine work from both features into dev, which sequence is correct?

A2,1,3,4
B1,3,2,4
C3,2,1,4
D1,2,3,4
Attempts:
2 left
💡 Hint

Start by switching to the target branch before merging others.

Best Practice
expert
3:00remaining
Why prefer merging over overwriting work?

Why is it better to use git merge to combine work instead of manually copying files and committing?

ABecause git merge deletes old files automatically.
BBecause manually copying files is faster and safer.
CBecause git merge preserves history and tracks changes from all contributors.
DBecause manual copying avoids merge conflicts.
Attempts:
2 left
💡 Hint

Think about how git helps keep track of who changed what and when.

Practice

(1/5)
1. What does the git merge command do in a project?
easy
A. It creates a new branch from the current branch.
B. It deletes a branch permanently.
C. It combines changes from one branch into another branch.
D. It shows the history of commits in 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: Compare with other git commands

    Deleting branches is done with git branch -d, creating branches with git branch, and viewing history with git log. None of these combine work like merge.
  3. Final Answer:

    It combines changes from one branch into another branch. -> Option C
  4. Quick Check:

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

Solution

  1. Step 1: Recall the git merge syntax

    The correct syntax to merge a branch is git merge <branch-name>. So for branch 'feature', it is git merge feature.
  2. Step 2: Identify incorrect options

    Options with flags like -b, --create, or -d are not valid for merging branches.
  3. Final Answer:

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

    Merge syntax = git merge branch-name [OK]
Hint: Use 'git merge branch-name' to combine branches [OK]
Common Mistakes:
  • Adding wrong flags like -b or -d
  • Confusing merge with branch creation
  • Using incorrect command order
3. Given the following commands run in order:
git checkout main
git merge feature

What happens after these commands?
medium
A. The 'feature' branch is deleted.
B. The 'main' branch is reset to the state of 'feature'.
C. A new branch named 'feature' is created.
D. The changes from the 'feature' branch are combined into 'main'.

Solution

  1. Step 1: Analyze the commands

    First, git checkout main switches to the 'main' branch. Then, git merge feature merges changes from 'feature' into 'main'.
  2. Step 2: Understand the effect of merge

    The merge combines the work from 'feature' into 'main' without deleting or resetting branches.
  3. Final Answer:

    The changes from the 'feature' branch are combined into 'main'. -> Option D
  4. Quick Check:

    Checkout + merge = combine changes [OK]
Hint: Checkout target branch, then merge source branch [OK]
Common Mistakes:
  • Thinking merge deletes branches
  • Confusing merge with reset
  • Assuming merge creates new branches
4. You ran git merge feature but got a conflict error. What should you do next?
medium
A. Delete the 'feature' branch to fix the conflict.
B. Manually resolve conflicts in files, then commit the merge.
C. Run git merge --abort and ignore the changes.
D. Run git reset --hard to force merge.

Solution

  1. Step 1: Understand merge conflicts

    When a conflict occurs, Git stops the merge and asks you to fix conflicting files manually.
  2. Step 2: Resolve conflicts and complete merge

    You must open the conflicting files, fix the differences, then commit the merge to finish combining work.
  3. Final Answer:

    Manually resolve conflicts in files, then commit the merge. -> Option B
  4. Quick Check:

    Conflicts require manual fix + commit [OK]
Hint: Fix conflicts manually, then commit merge [OK]
Common Mistakes:
  • Deleting branches to fix conflicts
  • Aborting merge without resolving
  • Using reset to force merge ignoring conflicts
5. You have two branches: main and feature. Both have new commits. You want to combine them so main has all changes, but keep the history clear. Which sequence is best?
hard
A. Checkout main, run git merge feature, then push main.
B. Checkout feature, run git merge main, then delete main.
C. Delete feature, then copy files manually to main.
D. Checkout main, run git rebase feature, then push main.

Solution

  1. Step 1: Identify the goal

    You want main to have all changes from both branches and keep history clear.
  2. Step 2: Choose the correct merge approach

    Checking out main and merging feature combines work properly and keeps history intact. Rebasing rewrites history and is more complex.
  3. Final Answer:

    Checkout main, run git merge feature, then push main. -> Option A
  4. Quick Check:

    Merge feature into main to combine work [OK]
Hint: Merge feature into main branch to combine work safely [OK]
Common Mistakes:
  • Merging main into feature instead of the reverse
  • Deleting branches before merging
  • Using rebase without understanding history rewrite