# Merge

URL: https://softwaredictionary.org/terms/merge
Category: Version Control
Last updated: 2026-09-29

In short: A merge in Git combines the changes from one branch into another, joining separate lines of development back together into a single, shared history.

## What is a merge in Git?

Merging is how work done on separate branches comes back together. When you merge a feature branch into `main`, Git integrates the changes from the feature branch's commits, so `main` now includes the new work. The history of both branches is preserved.

Git merges in one of two main ways. If the target branch hasn't changed since the feature branch was created, Git performs a fast-forward merge, which simply moves the branch pointer ahead. If both branches have new commits, Git performs a three-way merge: it compares each branch with their common ancestor and records the combined result in a new merge commit that has two parents.

A merge conflict happens when both branches changed the same lines of the same file, so Git can't decide which version to keep. Git marks the conflicting sections with `<<<<<<<`, `=======`, and `>>>>>>>` markers, and you must edit the file, keep the correct content, and commit the result. It is like two people editing the same sentence in a shared document: someone has to decide the final wording.

Merge is often compared with rebase. Both bring changes from one branch into another, but merge keeps the history exactly as it happened, including merge commits, while rebase rewrites commits to create a straight, linear history. Merging is generally the safer choice for branches that other people also use.

## Key takeaways

- A merge integrates changes from one branch into another.
- A fast-forward merge just moves the pointer; a three-way merge creates a merge commit.
- Conflicts occur when both branches change the same lines and must be resolved by hand.
- Merge preserves history, while rebase rewrites it into a straight line.

## Example: Merging a branch and handling a conflict

```bash
# Switch to the branch you want to merge into
git switch main

# Bring in the changes from the feature branch
git merge feature/search-bar

# If there is a conflict: fix the marked files, then
git add src/search.ts
git commit            # completes the merge

# Or cancel the merge and go back to how things were
git merge --abort
```

## Frequently asked questions

**What is a merge conflict?**

A merge conflict occurs when two branches change the same part of a file in different ways and Git can't combine them automatically. You resolve it by editing the file to the correct final version, staging it with `git add`, and committing.

**What is the difference between merge and rebase?**

Merge combines branches and keeps their full history, adding a merge commit when needed. Rebase moves your commits on top of another branch, rewriting them to produce a clean, linear history.

**What is a squash merge?**

A squash merge combines all the commits from a branch into a single new commit on the target branch. It keeps the main history tidy, at the cost of losing the individual commits from the feature branch.

## Sources

- [Git documentation: git-merge](https://git-scm.com/docs/git-merge)

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
