Skip to main content

Git Merge

The git merge command is used to merge the branches. It is the positive conclusion of your decision to incorporate the changes you saw using git fetch command.

Once the user likes the changes made by themself on the remote repository or made by their teammates, they can merge these changes to the repository (remote and local). These changes which could have been from multiple branches are merged into a single branch. Although it is the responsibility of the user who is merging the changes to ensure their head pointer points to the same branch in which they want to merge the changes. Not adhering to this will create unnecessary inconsistencies in the repository.

Git Merge Syntax:

git merge <query>

Git Merge Common Usage

  • git merge <commit> : To merge the specified commit to currently active branch.


    git merge 8d1c506d6aae33a41258edd5636cd9b1c8e3fb92

  • git merge <branchname> : Suppose you have made many changes on a branch and want to merge all of that at a time. Use this command to merge the whole branch in an active branch


    git merge dev

You can learn more about the git merge command and its options in git-scm's documentation.

Merge Conflicts

When two branches are trying to merge, and both are edited at the same time and in the same file, Git won't be able to identify which version is to take for changes. Such a situation is called merge conflict. If such a situation occurs, it stops just before the merge commit so that you can resolve the conflicts manually.

To learn more about Merge conflicts and how to resolve them, click here.