Branches

Contents

Branches#

A branch is a reference to a commit, and can be moved to some future commit. This page gives an overview of the tools git has to work with branches.

Merging#

Merging is the case when you create the commit that takes changes two branches. Generally there are two possible cases:

Case Name

Description

History

1. Fast-Forward Merge

Occurs when the target branch (the one you are merging into) has no new commits since the feature branch diverged.

Git simply moves the target branch pointer forward to the new commit. No merge commit is created, and the history remains linear.

2. Three-Way Merge (or True Merge)

Occurs when the target branch has new commits (i.e., the branches have diverged). This matches the scenario you described in your first question.

Git compares the two branch tips and their common ancestor (merge base) to combine changes. A merge commit is created, which has two parent commits, preserving the history of both branches.

The commands you may need to merge branches:

  • The git merge <target_branch> merges the current branch with the selected one.

  • The command git checkout --ours/theirs <file> applies changes to the <file> from the current branch or merged one in the conflict case.

For more check the Merge page.