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
Recall & Review
beginner
What is a fast-forward merge in Git?
A fast-forward merge happens when the branch you want to merge has all the new commits ahead of the current branch, so Git just moves the current branch pointer forward without creating a new commit.
Click to reveal answer
beginner
When does Git perform a fast-forward merge automatically?
Git performs a fast-forward merge automatically when the current branch has no new commits since the branch to merge started, meaning the current branch can just move forward to the target commit.
Click to reveal answer
intermediate
How do you prevent Git from doing a fast-forward merge?
You can prevent a fast-forward merge by using the command git merge --no-ff <branch>, which forces Git to create a merge commit even if a fast-forward is possible.
Click to reveal answer
intermediate
What is the visual difference between a fast-forward merge and a regular merge?
A fast-forward merge moves the branch pointer forward in a straight line, while a regular merge creates a new commit that joins two branches, showing a branch and merge structure in the history.
Click to reveal answer
intermediate
Why might you choose to avoid fast-forward merges?
Avoiding fast-forward merges keeps the history clearer by showing when branches were merged, which helps understand the project timeline and review changes better.
Click to reveal answer
What does a fast-forward merge do in Git?
AReverts the last commit on the current branch
BCreates a new merge commit combining two branches
CMoves the current branch pointer forward without creating a new commit
DDeletes the source branch after merging
✗ Incorrect
A fast-forward merge simply moves the branch pointer forward when no new commits exist on the current branch.
Which command prevents Git from doing a fast-forward merge?
Agit merge --ff-only <branch>
Bgit checkout <branch>
Cgit rebase <branch>
Dgit merge --no-ff <branch>
✗ Incorrect
Using --no-ff forces Git to create a merge commit even if a fast-forward is possible.
When is a fast-forward merge NOT possible?
AWhen the current branch has new commits not in the other branch
BWhen the branches are identical
CWhen the source branch is ahead of the current branch
DWhen the repository is empty
✗ Incorrect
If the current branch has new commits, Git cannot just move the pointer forward; it needs a merge commit.
What does the Git history look like after a fast-forward merge?
AA branch with a merge commit
BA straight line with no merge commits
CMultiple parallel branches
DA detached HEAD state
✗ Incorrect
Fast-forward merges keep history linear without extra merge commits.
Why might developers prefer to create merge commits instead of fast-forward merges?
ATo keep a clear record of when branches were merged
BTo speed up the merge process
CTo delete the source branch automatically
DTo avoid conflicts
✗ Incorrect
Merge commits help track the integration points of branches clearly in history.
Explain what a fast-forward merge is and when Git uses it.
Think about how Git moves the branch pointer when no new commits exist on the current branch.
You got /3 concepts.
Describe how to force Git to create a merge commit even if a fast-forward merge is possible and why you might want to do that.
Consider how to keep the project history easier to understand.
You got /3 concepts.
Practice
(1/5)
1. What happens during a fast-forward merge in Git?
easy
A. The source branch is deleted automatically.
B. A new merge commit is always created.
C. The branch pointer moves forward without creating a new commit.
D. The commit history becomes non-linear.
Solution
Step 1: Understand fast-forward merge behavior
A fast-forward merge moves the branch pointer forward to the latest commit of the source branch without creating a new merge commit.
Step 2: Compare with other merge types
Unlike a normal merge, it does not create a new commit and keeps history linear.
Final Answer:
The branch pointer moves forward without creating a new commit. -> Option C
Quick Check:
Fast-forward merge = pointer moves forward [OK]
Hint: Fast-forward means no new commit, just pointer moves [OK]
Common Mistakes:
Thinking a merge commit is always created
Assuming source branch deletes automatically
Believing history becomes non-linear
2. Which Git command syntax performs a fast-forward merge of branch feature into main only if possible, otherwise aborts?
easy
A. git merge --squash feature
B. git merge feature
C. git merge --no-ff feature
D. git merge --ff-only feature
Solution
Step 1: Identify command for fast-forward only
The option --ff-only tells Git to merge only if it can fast-forward, otherwise it aborts.
Step 2: Compare other options
--no-ff disables fast-forward, --squash creates a single commit without merging, and plain git merge feature may create a merge commit.
Final Answer:
git merge --ff-only feature -> Option D
Quick Check:
Fast-forward only = --ff-only [OK]
Hint: Use --ff-only to ensure only fast-forward merges happen [OK]
Common Mistakes:
Using --no-ff disables fast-forward merges
Assuming plain merge always fast-forwards
Confusing --squash with fast-forward
3. Given the following Git commands, what is the output of git log --oneline main after merging?
git checkout main
# main points to commit A
git checkout -b feature
# feature branch created from A
git commit --allow-empty -m "Add feature commit"
# feature now points to commit B
git checkout main
git merge feature
medium
A. B
B. B\nA
C. A
D. Merge commit with A and B
Solution
Step 1: Understand branch states before merge
Main points to commit A. Feature branch adds commit B on top of A.
Step 2: Analyze merge behavior
Since main has no new commits after branching, merging feature into main will fast-forward main to B.
Final Answer:
B\nA -> Option B
Quick Check:
Fast-forward merge moves main to B [OK]
Hint: If main unchanged, merge moves pointer to feature commit [OK]
Common Mistakes:
Expecting merge commit creation
Thinking main stays at A
Confusing commit hashes output
4. You tried to fast-forward merge branch feature into main using git merge --ff-only feature, but Git returned an error. What is the most likely cause?
medium
A. The main branch has new commits not in feature.
B. The feature branch is behind main.
C. The feature branch has no commits.
D. You forgot to commit changes on feature branch.
Solution
Step 1: Understand --ff-only error cause
The --ff-only option fails if a fast-forward merge is not possible.
Step 2: Identify when fast-forward is impossible
If main has new commits not in feature, Git cannot fast-forward main to feature, causing the error.
Final Answer:
The main branch has new commits not in feature. -> Option A
Quick Check:
Fast-forward fails if main has new commits [OK]
Hint: Fast-forward fails if main moved ahead since branching [OK]
Common Mistakes:
Assuming feature must be behind main
Thinking empty feature branch causes error
Confusing uncommitted changes with merge errors
5. You have a main branch and a feature branch. Both have new commits since branching. You want to merge feature into main but keep history linear without merge commits. Which approach is best?
hard
A. Use git rebase main on feature, then fast-forward merge.
B. Use git merge --no-ff feature to force a merge commit.
C. Use git merge --ff-only feature and abort if not fast-forward.
D. Delete main and rename feature to main.
Solution
Step 1: Understand the problem with fast-forward
Since both branches have new commits, a fast-forward merge is not possible directly.
Step 2: Use rebase to linearize history
Rebasing feature onto main moves feature commits on top of main, enabling a fast-forward merge afterward.
Step 3: Perform fast-forward merge after rebase
After rebase, merging feature into main will be a fast-forward, keeping history linear without merge commits.
Final Answer:
Use git rebase main on feature, then fast-forward merge. -> Option A
Quick Check:
Rebase then merge = linear history [OK]
Hint: Rebase feature on main to enable fast-forward merge [OK]