Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

Merge

In Git, merging brings changes from one branch into another. The `git merge` command updates the branch you’re on using the branch you name.

Also known as: мерж, слияние веток, git merge

What a Git merge does

Imagine you added search on feature/search while a teammate fixed a bug on main. Merging the feature branch into main brings the search feature and the fix together. The direction matters: to update main, check out main first, then name feature/search in the merge command. A local merge neither deletes the source branch nor publishes anything to the remote repository.

What happens to the commit history?

  • Fast-forward: If main hasn’t diverged and its tip is an ancestor of the feature branch’s tip, Git can move main forward to that commit. There’s no need for a new commit.
  • Three-way merge: If both branches have added commits since they split, Git compares each branch tip with a shared starting point called the merge base. It uses those comparisons to combine changes. A regular successful merge of two diverged branches records the result in a merge commit whose two parents are the previous branch tips.
  • Already up to date: If the source branch’s tip is already in the current branch’s history, there’s nothing to integrate.

Example: merge a feature locally

Assuming your local main is up to date, run:

git switch main
git status
git merge feature/search

Use git status to check for unfinished work before starting. If both branches edited the same lines in incompatible ways, Git may stop and ask you to resolve a conflict. Edit the affected files to produce the intended result, stage them with git add, and use git merge --continue to finish. To abandon an in-progress merge instead, use git merge --abort.

Team workflows and common mistakes

On a shared repository, a pull request typically gives reviewers and automated checks a chance to catch problems before changes land. A hosting platform’s Squash and merge option creates a single ordinary commit on the target branch rather than making the individual feature commits part of its ancestry. Also, a clean merge is not proof of correct behavior. One branch might rename a configuration key while another adds a feature that reads the old key. Git can combine the edits without a conflict, but you still need tests to catch the mismatch.

What interviewers ask

You may be shown a commit graph and asked whether a merge can fast-forward, or asked to compare merge with rebase. A regular merge leaves existing commit IDs intact. A rebase typically reapplies commits on a different base, producing new IDs. That’s why rebasing a branch other people have already based work on requires coordination.