> ## 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.

# Merging Branches

> Combine changes from different branches

## Overview

Merging combines the changes from one branch into another. This is how you bring feature work back into your main branch.

## Merge Types

VibeHub supports two types of merges:

### Fast-Forward Merge

When the target branch hasn't changed since you branched off:

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

After:
main:     A---B---C---D
```

**Characteristics:**

* No merge commit needed
* History stays linear
* Cleanest merge type

### Merge Commit

When both branches have new commits:

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

After:
main:     A---B---E---M
               \     /
feature:        C---D
```

**Characteristics:**

* Creates a merge commit (M)
* Preserves both histories
* Shows where branches combined

## Performing a Merge

<Steps>
  <Step title="Compare Branches">
    First, [compare your branches](/version-control/comparing-branches) to see what will be merged
  </Step>

  <Step title="Click Merge">
    If your source branch is ahead of the target, click the **Merge** button
  </Step>

  <Step title="Review Merge Dialog">
    The merge dialog shows:

    * Source and target branches
    * Merge type (fast-forward or merge commit)
    * Number of commits being merged
  </Step>

  <Step title="Add Merge Message (if needed)">
    For merge commits, you can customize the commit message
  </Step>

  <Step title="Confirm">
    Click **Merge** to complete the operation
  </Step>
</Steps>

## The Merge Dialog

When you initiate a merge, you'll see:

| Element       | Description                            |
| ------------- | -------------------------------------- |
| Source branch | The branch with changes you're merging |
| Target branch | The branch receiving the changes       |
| Merge type    | Fast-forward or merge commit           |
| Commit count  | Number of commits being merged         |
| Merge message | Editable message for merge commits     |

## Protected Branch Warnings

<Warning>
  If you're merging into a protected branch, you'll see a warning. Make sure you have the necessary permissions.
</Warning>

Protected branches may have additional requirements like:

* Code review approval
* Passing tests
* Admin override

## After the Merge

Once merged successfully:

1. The target branch now includes all changes from the source
2. You'll see a success confirmation with the merge commit ID (if applicable)
3. The source branch still exists (you can delete it if done)

## Cleaning Up

After merging a feature branch, consider deleting it:

1. Go to the branch selector
2. Find your merged branch
3. Click the delete icon
4. Confirm deletion

<Tip>
  Deleting merged branches keeps your branch list clean. The commits are preserved in the target branch.
</Tip>

## Handling Diverged Branches

If branches have diverged significantly:

1. **Option A:** Merge anyway and create a merge commit
2. **Option B:** Update your feature branch first by merging main into it
3. **Option C:** Use the CLI for more advanced conflict resolution

## Merge Best Practices

<AccordionGroup>
  <Accordion title="Keep branches short-lived" icon="clock">
    Merge feature branches quickly to avoid large divergences.
  </Accordion>

  <Accordion title="Update before merging" icon="rotate">
    If main has changed, consider updating your branch first to catch conflicts early.
  </Accordion>

  <Accordion title="Review before merging" icon="eye">
    Always compare branches before merging to understand what's changing.
  </Accordion>

  <Accordion title="Write clear merge messages" icon="pen">
    For merge commits, explain what feature or fix is being integrated.
  </Accordion>
</AccordionGroup>

## Troubleshooting

### Can't Merge

If the merge button is disabled:

* You might not have write access
* The branches might be identical
* The source might not be ahead of the target

### Merge Conflicts

VibeHub will warn you if conflicts are detected. For complex conflicts, you may need to:

1. Pull the branches locally
2. Resolve conflicts in your editor
3. Push the resolved version

## Next Steps

<CardGroup cols={2}>
  <Card title="View Commits" icon="code-commit" href="/version-control/commits">
    See your merge in the commit history
  </Card>

  <Card title="Manage Branches" icon="code-branch" href="/version-control/branches">
    Clean up or create new branches
  </Card>
</CardGroup>
