Merging branches
You can integrate several branches by using the git merge command.
Consider the situation below. There are two branches: a bugfix
branch with a few commits coming off the main
branch.

In this case, merging bugfix
back into main
is not much of an issue. That’s because main
has not changed since bugfix
was created. Git will merge this by moving the main
position to the latest position of bugfix.
This merge is called a fast-forward
.

In the example below, however, main
has been updated several times since bugfix
was branched out. The changes from bugfix
and main
must be combined when a merge is executed on these two branches.

For this sort of merge, a merge commit
is created, and the main
position is updated to the newly created merge commit.

Even when a fast-forward merge is possible, you could still explicitly force it to merge without a fast-forward merge.

As shown above, a non-fast-forward merge leaves the bugfix
branch as it is. This gives you a clearer picture of the feature branch bugfix.
You can easily find where the feature branch starts or ends and track the changes made to the feature branch.