Git concepts: merging
Merging in Git is the process of combining the changes from one branch into another. It is typically used when a feature development or bug fix, carried out in a separate branch, is complete and needs to be integrated into the main codebase.
The 'git merge' command takes the contents of a source branch and integrates it with the target branch. Git will automatically combine the changes from each branch and create a new commit in the target branch.
However, if the same part of the same file has been modified in both branches, Git won't be able to figure out which version to use. When such a situation occurs, it results in a merge conflict which needs to be resolved manually.
There are two types of merges in Git:
Fast-forward merge: This occurs when there is a linear path from the current branch to the target branch. Instead of creating a new commit, Git just moves the current branch pointer to the target branch's pointer.
Three-way merge: This is used when there is not a linear path between branches. Git will use three commits: the two branch tips and their common ancestor, to create a new commit.
In summary, merging in Git is a way of integrating changes from one branch into another, combining different lines of development, and providing a way to join diverged commit histories.