---
title: "Branching, merging and resolving a conflict"
description: "Git compares branch tips with a merge base and can combine many text changes automatically. Conflicts need a person to decide the required behavior. Rebase replays commits on a new base, changing thei"
canonical: https://lightmysky.com/learn/computing/branching-merging-and-resolving-a-conflict-mt_l3vFbU7L3E
source: https://lightmysky.com/learn/computing/branching-merging-and-resolving-a-conflict-mt_l3vFbU7L3E.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Branching, merging and resolving a conflict

Git compares branch tips with a merge base and can combine many text changes automatically. Conflicts need a person to decide the required behavior. Rebase replays commits on a new base, changing their identities and ancestry. Rewriting commits that teammates use needs coordination.

Subject: Computing · Area: Software Engineering · Ages 18 to 19
Page: https://lightmysky.com/learn/computing/branching-merging-and-resolving-a-conflict-mt_l3vFbU7L3E

## Ready when they can

- Merge two branches and identify the common ancestor the merge used
- Resolve a conflict by checking what the combined code must do instead of choosing a side without checking
- Say when a rebase is a better choice than a merge, and when it is a worse one

## Lesson: Merging work without losing meaning

You have followed commit parents and branch labels. In a simple branch history, Git compares both tips with their most recent shared ancestor, the merge base. Separate edits or identical changes can often merge automatically. Incompatible edits to overlapping text may cause a conflict. A clean text merge can still break behavior, so check the result.

**Example.** At a shared commit, git switch -c feature creates a branch label and switches to it. After main and feature gain separate commits, git switch main followed by git merge feature starts combining their work. A completed ordinary merge of divergent branches adds a commit with both tips as parents. If main is an ancestor of feature, a fast-forward can move main to feature's tip without adding a commit.

If a merge pauses for a conflict, inspect the base and both edits. Edit the file to give the required behavior and remove conflict markers. Run relevant tests. Stage each resolved file with git add, then finish this merge with git commit. Editing alone does not tell Git that the file is resolved.

*(drawing: Check the resolved behavior before staging the files and completing this merge.)*

**Example.** Main renames a setting while feature adds checks for its value. Both changes are required. Keep the new name and make the new checks use it. Test valid and invalid values. Either complete side alone may omit required behavior, so inspect both before choosing the final code.

An ordinary rebase replays selected commits on a new base. Suppose feature's C has parent A, while main's B also has parent A. Replaying C onto B creates C' with parent B and a new commit ID. The feature label moves to C'. Author dates normally remain; committer dates normally change. This new chain does not erase every reference to the old commits. Rebase options can preserve merge structure.

Rebasing private work onto an updated base can make review easier. Merging shared work keeps the existing commits and their ancestry. Rewriting commits that teammates use can make their histories diverge. Prefer merging when you need to preserve shared history. If shared history must be rewritten, agree on how everyone will update their work first.

**Recap.** Compare with the merge base, resolve the conflict to give the required behavior and test. Rebase creates new commits; coordinate before rewriting work that teammates use.

*Original teaching, questions and flashcards about Git merging, conflict resolution and rebasing, written for this dataset.*

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Version Control as a Graph of Commits](https://lightmysky.com/learn/computing/version-control-as-a-graph-of-commits-mt_oKsDRKirMy)

## Opens up

- [Code review: reading a change you did not write](https://lightmysky.com/learn/computing/code-review-reading-a-change-you-did-not-write-mt_Hhe1Ou709s)
- [Continuous Integration and the Build Pipeline](https://lightmysky.com/learn/computing/continuous-integration-and-the-build-pipeline-mt_z__G4nfjwh)
