Merge Branches – Git Merge

Understanding Different Git Merge Types

git merge is the command used when you want to merge branches. The merge operation can be done through the Remote Repository on the GitHub platform; it will be explained further in the next chapter.

When you run the git merge command, you need to run the command from the branch you want to continue to work on and specify a target branch name that you want to merge with the current branch.

There are four main cases for merge actions depending on the status of branches and command options.

  1. Fast-Forward Merge
  2. Non-Fast-Forward Merge
  3. Non-Fast Forward Merge with the "--no-ff" option
  4. Squash Merge

1. Fast-Forward Merge

When you are merging a child branch that is ahead of the parent branch (no changes were made to the parent branch after the point when you created the child branch), the git merge command simply brings changes made in the child branch into the parent branch without creating a new commit. In this case, the status of the branches will shift to the one shown in the following illustration.

This command moves the HEAD of the master branch forward to the point of the HEAD of Branch_A. The merge command doesn't impact Branch_A. The master branch simply becomes the same as the status of Branch_A.