Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git collaboration
  6. Integrating branches
  7. Merging branches
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

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.

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.

Fast-forward merge

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.

It has advanced more than when a branch is divided

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

Merge commit incorporating both changes

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

Non 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.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life