Merging Basics

How to safely integrate diverged histories and bring features into the main branch.

Version Control5 min readConcept 10 of 29

Integrating Histories

git merge is the command used to join two or more development histories together.

It incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch.

Why it matters

Web developers constantly build new features, fix bugs, or experiment with UI updates in isolated branches.

git merge allows them to safely integrate these parallel lines of work into a central integration branch (like main or develop) so the application can be deployed with everyone's contributions combined.

How it works

Git takes two commit pointers (usually the current branch tip and the target branch tip) and finds their common base commit (the merge base).

It then creates a new 'merge commit' that combines the changes from both sequences. If the history is linear, Git performs a 'fast-forward' merge by simply moving the current branch pointer forward without creating a new merge commit.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1What does the `git merge` command fundamentally do?
  2. 2You want to merge the `header-fix` branch into the `main` branch. What must you do first before running the merge command?
  3. 3What happens when Git encounters a 'merge conflict'?

Remember this

  • Git merge pulls INTO where you currently stand (your active branch).
  • A fast-forward merge simply moves the pointer; a 3-way merge creates a new commit.
  • Merge conflicts require human resolution when lines overlap.

Done with this concept?

Mark it complete to track your progress. No login needed.