> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vibehub.co.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Comparing Branches

> See the differences between branches before merging

## Overview

Before merging branches, you'll want to understand what's different between them. VibeHub's branch comparison shows you exactly how branches have diverged.

## Accessing Branch Comparison

<Steps>
  <Step title="Open Project Settings">
    Navigate to your project and click the **Settings** tab
  </Step>

  <Step title="Find Branch Management">
    Scroll to the branch management section
  </Step>

  <Step title="Select Branches to Compare">
    Choose the source and target branches from the dropdowns
  </Step>
</Steps>

## Understanding the Comparison

### Ahead and Behind

The comparison shows two key metrics:

| Metric     | Meaning                                        |
| ---------- | ---------------------------------------------- |
| **Ahead**  | Commits in source branch that aren't in target |
| **Behind** | Commits in target branch that aren't in source |

### Status Messages

Based on the comparison, you'll see one of these status messages:

<AccordionGroup>
  <Accordion title="Branches are identical" icon="equals">
    Both branches have the same commits. No merge needed.
  </Accordion>

  <Accordion title="X commits ahead" icon="arrow-up">
    The source branch has commits that the target doesn't have. You can merge these changes into the target.
  </Accordion>

  <Accordion title="X commits behind" icon="arrow-down">
    The target branch has commits that the source doesn't have. You may want to update your source branch first.
  </Accordion>

  <Accordion title="Branches have diverged" icon="code-branch">
    Both branches have unique commits. A merge commit will be needed to combine them.
  </Accordion>
</AccordionGroup>

## Visual Indicators

The comparison UI uses visual cues to help you understand the state:

* **Green arrow up** - Commits ahead (source has changes to merge)
* **Red arrow down** - Commits behind (target has changes you don't)
* **Branch icons** - Show which branch is which

## Common Scenarios

### Simple Feature Branch

```
main:     A---B---C
               \
feature:        D---E
```

**Result:** Feature is 2 commits ahead, 0 behind. Fast-forward merge possible.

### Updated Main Branch

```
main:     A---B---C---F
               \
feature:        D---E
```

**Result:** Feature is 2 ahead, 1 behind. Branches have diverged.

### Identical Branches

```
main:     A---B---C
feature:  A---B---C
```

**Result:** Branches are identical. Nothing to merge.

## Using Comparison for Code Review

Branch comparison is useful for:

1. **Pre-merge review** - See all changes before merging
2. **Understanding scope** - Know how much has changed
3. **Identifying conflicts** - Diverged branches may have conflicts
4. **Planning merges** - Decide if you should update your branch first

## From Comparison to Merge

If the comparison shows your source branch is ahead, you'll see a **Merge** button:

1. Review the commit count
2. Click **Merge** when ready
3. See [Merging](/version-control/merging) for details on the merge process

<Tip>
  Always compare branches before merging to avoid surprises. If branches have diverged significantly, consider updating your feature branch first.
</Tip>

## Next Steps

<CardGroup cols={2}>
  <Card title="Merge Branches" icon="code-merge" href="/version-control/merging">
    Combine your branch changes
  </Card>

  <Card title="Branch Basics" icon="code-branch" href="/version-control/branches">
    Review branch fundamentals
  </Card>
</CardGroup>
