CodeBlanks Logo Icon CodeBlanks

Fast-forward

Learn when a fast-forward merge happens.

What Is Fast-Forward?

Fast-forward is a simple type of merge that can occur when the target branch has no new commits independent of the source branch. Git advances the target branch pointer to the latest commit on the source branch without creating a new merge commit.

main:    A
              \
feature:       B -- C

# main advances to C

The resulting commit history remains linear.

Linear Commit History

After a fast-forward, commits follow a single line. There is no separate commit indicating that the branches were merged.

A -- B -- C
     main  feature

This method is useful when you want to keep the history between two branches linear. A normal fast-forward cannot occur if the target branch has an independent commit.

Practice Prepare a Fast-Forward Command

You are on the main branch and want to merge the progress from topic. Assign the command to the mergeCommand variable and print it.

Starter code

terminal
const mergeCommand = "";

// Komutu ekrana yazdır

Sample solution

terminal
const mergeCommand = "git merge topic";

console.log(mergeCommand);

Expected output

git merge topic

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does Git do during a fast-forward merge?

  • Combines commit messages
  • Advances the target branch pointer Correct answer
  • Deletes both branches
  • Always creates a new merge commit

Explanation: During a fast-forward, the target branch pointer moves to the commit reached by the source branch. No additional merge commit is needed.

2 Write the Fast-Forward Merge Command

Question
git switch main
____
Answer
git switch main
git merge feature

Explanation: When main is the target branch, git merge feature incorporates the progress from feature. Git performs a fast-forward when the conditions allow it.

3 Fast-Forward Characteristics

Term Meaning
Fast-forward Advances the branch pointer
Doğrusal geçmiş Commits in a single line
Merge commit Not created in fast-forward
Bağımsız commit Can prevent fast-forward

All lessons in Beginner