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

# Merge

> Merge branches and resolve conflicts

wit provides an improved merge experience with structured conflict resolution.

## merge

Merge a branch into the current branch.

```bash theme={null}
wit merge <branch> [options]
```

### Options

| Option             | Description                              |
| ------------------ | ---------------------------------------- |
| `--no-commit`      | Perform merge but don't create a commit  |
| `--abort`          | Abort the current merge                  |
| `--continue`       | Continue merge after resolving conflicts |
| `--conflicts`      | Show current conflicts                   |
| `--resolve <file>` | Mark a file as resolved                  |

### Examples

```bash theme={null}
# Merge a branch
wit merge feature-branch

# Merge without auto-commit
wit merge feature-branch --no-commit
```

***

## Merge Workflow

### Simple Merge (No Conflicts)

```bash theme={null}
# Ensure you're on the target branch
wit switch main

# Merge the feature branch
wit merge feature-login
```

Output:

```
Merging feature-login into main...
Merge successful!
```

### Merge with Conflicts

When conflicts occur:

```bash theme={null}
wit merge feature-branch
```

Output:

```
Merging feature-branch into main...
CONFLICT: src/index.ts
CONFLICT: src/config.ts

Automatic merge failed. Fix conflicts and run:
  wit merge --continue
```

***

## Conflict Resolution

### View Conflicts

```bash theme={null}
wit merge --conflicts
```

Output:

```
Conflicting files:
  1. src/index.ts (3 conflicts)
  2. src/config.ts (1 conflict)
```

### Structured Conflict Format

Unlike Git's inline markers, wit uses structured JSON for conflicts:

```json theme={null}
{
  "file": "src/index.ts",
  "conflicts": [
    {
      "line": 15,
      "ours": "const timeout = 5000;",
      "theirs": "const timeout = 10000;",
      "base": "const timeout = 3000;"
    }
  ]
}
```

### Resolving Conflicts

1. **Edit the file** to fix conflicts
2. **Mark as resolved:**
   ```bash theme={null}
   wit merge --resolve src/index.ts
   ```
3. **Complete the merge:**
   ```bash theme={null}
   wit merge --continue
   ```

### Abort a Merge

If you want to cancel the merge:

```bash theme={null}
wit merge --abort
```

***

## Visual Conflict Resolution

For complex conflicts, use the visual interface:

```bash theme={null}
wit web
```

The web UI provides:

* Side-by-side diff view
* Click to choose "ours" or "theirs"
* Manual editing for custom resolution
* Preview of merged result

***

## Merge Example

Here's a complete merge workflow:

```bash theme={null}
# 1. Start on main branch
wit switch main

# 2. Attempt merge
wit merge feature-auth

# 3. If conflicts occur, view them
wit merge --conflicts

# 4. Open and edit conflicting files
# (or use wit web for visual resolution)

# 5. Mark files as resolved
wit merge --resolve src/auth.ts
wit merge --resolve src/config.ts

# 6. Complete the merge
wit merge --continue

# 7. Verify the merge
wit log --oneline -n 5
```

***

## Undo a Merge

Made a mistake? Just undo it:

```bash theme={null}
wit undo
```

This works whether the merge:

* Completed successfully
* Is still in progress
* Has conflicts

***

## Merge Strategies

wit currently supports recursive merge strategy (similar to Git's default). Additional strategies are planned for future releases.

## Tips

<Tip>
  Before merging, ensure your branch is up to date:

  ```bash theme={null}
  wit switch feature-branch
  wit status  # Check for uncommitted changes
  wit switch main
  wit merge feature-branch
  ```
</Tip>

<Warning>
  Don't use `--force` unless you really mean it. The undo command is your friend if something goes wrong.
</Warning>
