Bird
Raised Fist0
Gitdevops~10 mins

Merge commit creation in Git - Interactive Code Practice

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
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the command to merge branch 'feature' into the current branch.

Git
git merge [1]
Drag options to blanks, or click blank then click option'
Acommit
Bfeature
Ccheckout
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'commit' instead of the branch name.
Confusing 'checkout' with 'merge'.
Trying to 'push' instead of merging.
2fill in blank
medium

Complete the command to create a merge commit even if the merge could be fast-forwarded.

Git
git merge --[1] feature
Drag options to blanks, or click blank then click option'
Asquash
Bno-commit
Cno-ff
Dabort
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--no-commit' which prevents committing the merge.
Using '--squash' which combines commits without a merge commit.
Using '--abort' which cancels the merge.
3fill in blank
hard

Fix the error in the command to merge branch 'dev' into current branch with a merge commit.

Git
git merge [1] --no-ff
Drag options to blanks, or click blank then click option'
Adev
B--no-ff
Ccommit
Dmerge
Attempts:
3 left
💡 Hint
Common Mistakes
Putting options before the branch name.
Using 'merge' or 'commit' as branch names.
4fill in blank
hard

Fill both blanks to create a merge commit with a custom message 'Merge feature branch'.

Git
git merge [1] -m [2]
Drag options to blanks, or click blank then click option'
Afeature
B"Merge feature branch"
C"Merge commit"
Ddevelop
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong branch name.
Not quoting the message properly.
5fill in blank
hard

Fill all three blanks to merge 'hotfix' branch with no fast-forward and a custom message 'Hotfix merge'.

Git
git merge [1] [2] -m [3]
Drag options to blanks, or click blank then click option'
Ahotfix
B--no-ff
C"Hotfix merge"
D--squash
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--squash' which does not create a merge commit.
Not quoting the message.
Putting options in the wrong order.

Practice

(1/5)
1. What does a git merge <branch-name> command do in Git?
easy
A. Combines changes from the specified branch into the current branch with a merge commit
B. Deletes the specified branch from the repository
C. Creates a new branch named after the specified branch
D. Resets the current branch to the specified branch's state without merging

Solution

  1. Step 1: Understand the purpose of git merge

    The git merge <branch-name> command is used to combine changes from another branch into the current branch.
  2. Step 2: Identify the result of the merge

    This operation creates a merge commit that records the integration of changes from both branches.
  3. Final Answer:

    Combines changes from the specified branch into the current branch with a merge commit -> Option A
  4. Quick Check:

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

Solution

  1. Step 1: Recall the basic merge syntax

    The correct syntax to merge a branch is git merge <branch-name> without extra flags for a normal merge commit.
  2. Step 2: Evaluate the options

    git merge feature matches the correct syntax. The other options use invalid or unrelated flags.
  3. Final Answer:

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

    Simple merge = git merge branch [OK]
Hint: Use 'git merge branch-name' to merge simply [OK]
Common Mistakes:
  • Adding unnecessary flags like -b or --delete
  • Confusing merge with branch creation or deletion commands
  • Using reset flag which is unrelated to merge
3. Given the following commands executed in order:
git checkout main
git merge feature

What will Git do if there are no conflicts between main and feature and the branches have diverged?
medium
A. Reset main branch to feature branch state without commit
B. Delete the feature branch automatically
C. Create a merge commit combining changes from feature into main
D. Fail with an error asking to resolve conflicts

Solution

  1. Step 1: Understand the merge process without conflicts

    If there are no conflicts and the branches have diverged, Git will automatically create a merge commit combining changes from the feature branch into main.
  2. Step 2: Confirm no branch deletion or errors occur

    Git does not delete branches or reset branches automatically during merge without conflicts.
  3. Final Answer:

    Create a merge commit combining changes from feature into main -> Option C
  4. Quick Check:

    No conflicts + diverged = auto merge commit [OK]
Hint: No conflicts + diverged means merge commit created automatically [OK]
Common Mistakes:
  • Thinking feature branch is deleted after merge
  • Expecting errors when no conflicts exist
  • Confusing merge with reset or branch deletion
4. You run git merge feature but Git reports conflicts. What should you do next to complete the merge?
medium
A. Delete the current branch and recreate it to fix conflicts
B. Run git merge --abort to cancel the merge and delete the feature branch
C. Run git reset --hard to force merge without fixing conflicts
D. Manually fix conflicts in files, then run git add and git commit

Solution

  1. Step 1: Understand conflict resolution process

    When Git reports conflicts, you must manually fix the conflicting files by editing them.
  2. Step 2: Complete the merge after fixing conflicts

    After fixing, stage the changes with git add and finish the merge with git commit.
  3. Final Answer:

    Manually fix conflicts in files, then run git add and git commit -> Option D
  4. Quick Check:

    Fix conflicts, add, commit to complete merge [OK]
Hint: Fix conflicts manually, then add and commit [OK]
Common Mistakes:
  • Aborting merge and deleting branches unnecessarily
  • Using reset to skip conflict resolution
  • Deleting branches instead of resolving conflicts
5. You want to merge branch feature into main but avoid creating a merge commit. Which command should you use?
hard
A. git merge --no-ff feature
B. git merge --squash feature
C. git merge --ff-only feature
D. git merge --abort feature

Solution

  1. Step 1: Understand merge commit creation options

    The --squash option merges changes without creating a merge commit by combining all changes into one commit.
  2. Step 2: Compare other options

    --no-ff forces a merge commit, --ff-only only merges if fast-forward is possible, and --abort cancels merges.
  3. Final Answer:

    git merge --squash feature -> Option B
  4. Quick Check:

    Squash merges without merge commit [OK]
Hint: Use --squash to merge without merge commit [OK]
Common Mistakes:
  • Using --no-ff which forces merge commit
  • Confusing --ff-only with no commit creation
  • Trying to abort merge to avoid commit