stackademic

The leading education platform for anyone with an interest in software development.

Merge

Combine branch histories with merge commits or fast-forward

Overview

Merging integrates changes from one branch into another. Git creates a merge commit when histories diverge, or fast-forwards when the target branch has no new commits. Resolve conflicts manually when the same lines were edited.

Syntax / Usage

# Merge feature into current branch
git switch main
git pull origin main
git merge feature/login

# Merge with explicit message
git merge feature/login -m "Merge feature/login into main"

# Abort conflicted merge
git merge --abort

# After resolving conflicts
git add conflicted-file.ts
git commit   # completes merge if needed

Examples

Merge a completed feature:

git switch main
git merge --no-ff feature/checkout -m "Merge checkout flow"
git push origin main

Inspect conflict markers:

<<<<<<< HEAD
const tax = 0.08
=======
const tax = 0.10
>>>>>>> feature/pricing

Edit to the correct version, remove markers, then git add and git commit.

Common Mistakes

  • Merging without updating the target branch first (git pull)
  • Leaving conflict markers in committed files
  • Merging huge branches infrequently—prefer smaller PRs
  • Using merge when a rebase would keep history linear (team preference varies)

See Also

branch rebase commit remote