Branches and merging · Lesson 6 of 15
Merge: fast-forward and three-way
Combine a branch and understand when Git moves a name or creates a merge commit.
If main has not moved since feature began, Git can fast-forward by moving main to the same commit. If both sides moved, a three-way merge uses their common ancestor and usually creates a merge commit.
Choose target branch
git merge feature
Fast-forward or three-way
Test the result
git init -q -b main echo "base" > app.txt git add app.txt git commit -q -m "Base" git switch -q -c feature echo "ready" > feature.txt git add feature.txt git commit -q -m "Add feature" git switch -q main git merge -q feature git log --format=%s
Merge into the branch you are on: to bring feature into main, switch to main then git merge feature. After testing, the feature name can be deleted because main still reaches its commits.
Quick question
Does a fast-forward create a merge commit?
Exercise
Make Feature ready on feature, merge it into main, then print subjects.
Feature ready Base
git init -q -b main echo "base" > app.txt git add app.txt git commit -q -m "Base" git switch -q -c feature git log --format=%s
Learn more from
Played 0 of 2 games
Sign in to save your progress and earn XP.