Merging

This YouTube video was created by GitHub Training & Guides.

Mergingopen in new window is the convergence of two parallel lines of development or the combining of commits of two different branches. The process of merging is accomplished using the git merge command. Start by switching to the branch to merge into, then call the git merge command followed by the name of the branch to be merged.

git checkout main
git merge new-branch

Merge Conflicts

Merge conflictsopen in new window occur when Git is unable to complete a merge, and often is the result of different changes being made to the same part of the same file. When this occurs, Git will indicate that a merge conflict has occurred.

Instead of merging the conflicting changes, Git will add standard conflict-resolution markers to the files that have conflicts.

<<<<<<< HEAD:index.html
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">please contact us at support@github.com</div>
>>>>>>> new-branch:index.html

The top section indicates the current change. The bottom section is the incoming change. The merge must be completed manually and markers removed to resolve this conflict. Once all of the conflicts have been resolved, the git add command is run on each conflicting file. Finally, running the git commit command will fully merge the branches.