Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/public/llms.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions docs/src/content/docs/merge.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: "wt merge"
description: "Merge current branch into the target branch. Squash & rebase, fast-forward the target branch, remove the worktree."
description: "Merge a branch into the target branch. Squash & rebase, fast-forward the target branch, remove the worktree."
sidebar:
order: 12
---
<!-- ⚠️ AUTO-GENERATED from `wt merge --help-page` — edit src/cli/mod.rs to update -->

Merge current branch into the target branch. Squash & rebase, fast-forward the target branch, remove the worktree.
Merge a branch into the target branch. Squash & rebase, fast-forward the target branch, remove the worktree.

Unlike `git merge`, this merges the current branch into the target branch — not the target into current. Similar to clicking "Merge pull request" on GitHub, but locally. The target defaults to the default branch.
Unlike `git merge`, this merges the source branch into the target branch — not the target into current. Similar to clicking "Merge pull request" on GitHub, but locally. The source defaults to the current branch; the target defaults to the default branch.

<figure class="demo">
<picture>
Expand Down Expand Up @@ -43,6 +43,15 @@ Merge to a different branch:
$ wt merge develop
```

Merge another worktree's branch without leaving the current worktree:

```console
$ wt merge --branch feature/auth
$ wt merge develop --branch feature/auth
```

The source branch must have a checked-out worktree. Commit, squash, rebase, and hooks use that worktree and its project configuration. Cleanup removes the source worktree; the invoking worktree stays in place. A rebase conflict is left in the source worktree to resolve or abort.

Keep the worktree after merging:

```console
Expand Down Expand Up @@ -83,7 +92,7 @@ $ wt merge --no-commit --no-rebase
4. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](/hook/).
5. **Merge** — Fast-forward merge to the target branch ([`wt step push`](/step/#wt-step-push)). With `--no-ff`, a merge commit is created instead — semi-linear history after the default rebase, while explicit `--no-rebase` preserves the graph produced by earlier steps before adding the merge commit. Non-fast-forward merges are rejected.
6. **Pre-remove hooks** — Hooks run before removing worktree. Failures abort.
7. **Cleanup** — Removes the worktree and branch. Use `--no-remove` to keep the worktree. When already on the target branch, in the primary worktree, or locked, the worktree is preserved.
7. **Cleanup** — Removes the worktree and branch. Use `--no-remove` to keep the worktree. When already on the target branch, in the primary worktree, locked, or containing another registered worktree, the worktree is preserved.
8. **Post-remove + post-merge hooks** — Run in background after cleanup.

Use `--no-commit` to skip committing uncommitted changes and squashing; rebase still runs by default and can rewrite commits unless `--no-rebase` is passed. Combining both flags preserves the exact source graph and requires the target to be its ancestor. Useful after preparing commits manually with `wt step commit`. Requires a clean working tree.
Expand Down Expand Up @@ -114,7 +123,7 @@ lint = "cargo clippy"
## Command reference

```text wt-command-reference
wt merge - Merge current branch into the target branch
wt merge - Merge a branch into the target branch

Squash & rebase, fast-forward the target branch, remove the worktree.

Expand All @@ -127,6 +136,9 @@ Arguments:
Defaults to default branch.

Options:
-b, --branch <BRANCH>
Branch to merge from (defaults to current worktree)

--no-squash
Skip commit squashing

Expand Down
20 changes: 16 additions & 4 deletions plugins/worktrunk/skills/worktrunk/reference/merge.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions skills/worktrunk/reference/merge.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ pub(crate) struct RemoveArgs {

#[derive(Args)]
pub(crate) struct MergeArgs {
/// Branch to merge from (defaults to current worktree)
#[arg(short, long, add = crate::completion::worktree_only_completer(), value_parser = crate::cli::non_empty_branch)]
pub(crate) branch: Option<String>,

/// Target branch
///
/// Defaults to default branch.
Expand Down Expand Up @@ -1429,11 +1433,11 @@ Detached worktrees have no branch name. Pass the worktree path instead: `wt remo
"#)]
Remove(RemoveArgs),

/// Merge current branch into the target branch
/// Merge a branch into the target branch
///
/// Squash & rebase, fast-forward the target branch, remove the worktree.
#[command(
after_long_help = r#"Unlike `git merge`, this merges the current branch into the target branch — not the target into current. Similar to clicking "Merge pull request" on GitHub, but locally. The target defaults to the default branch.
after_long_help = r#"Unlike `git merge`, this merges the source branch into the target branch — not the target into current. Similar to clicking "Merge pull request" on GitHub, but locally. The source defaults to the current branch; the target defaults to the default branch.

<!-- demo: wt-merge.gif 1600x900 | Creating a worktree, committing in it, and merging it away -->
## Examples
Expand Down Expand Up @@ -1462,6 +1466,15 @@ Merge to a different branch:
$ wt merge develop
```

Merge another worktree's branch without leaving the current worktree:

```console
$ wt merge --branch feature/auth
$ wt merge develop --branch feature/auth
```

The source branch must have a checked-out worktree. Commit, squash, rebase, and hooks use that worktree and its project configuration. Cleanup removes the source worktree; the invoking worktree stays in place. A rebase conflict is left in the source worktree to resolve or abort.

Keep the worktree after merging:

```console
Expand Down Expand Up @@ -1502,7 +1515,7 @@ $ wt merge --no-commit --no-rebase
4. **Pre-merge hooks** — Hooks run after rebase, before merge. Failures abort. See [`wt hook`](/hook/).
5. **Merge** — Fast-forward merge to the target branch ([`wt step push`](/step/#wt-step-push)). With `--no-ff`, a merge commit is created instead — semi-linear history after the default rebase, while explicit `--no-rebase` preserves the graph produced by earlier steps before adding the merge commit. Non-fast-forward merges are rejected.
6. **Pre-remove hooks** — Hooks run before removing worktree. Failures abort.
7. **Cleanup** — Removes the worktree and branch. Use `--no-remove` to keep the worktree. When already on the target branch, in the primary worktree, or locked, the worktree is preserved.
7. **Cleanup** — Removes the worktree and branch. Use `--no-remove` to keep the worktree. When already on the target branch, in the primary worktree, locked, or containing another registered worktree, the worktree is preserved.
8. **Post-remove + post-merge hooks** — Run in background after cleanup.

Use `--no-commit` to skip committing uncommitted changes and squashing; rebase still runs by default and can rewrite commits unless `--no-rebase` is passed. Combining both flags preserves the exact source graph and requires the target to be its ancestor. Useful after preparing commits manually with `wt step commit`. Requires a clean working tree.
Expand Down
4 changes: 2 additions & 2 deletions src/commands/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
//! set. (Aliases get the property structurally instead: the body is frozen
//! into `AliasEntry` before the gate, like `ApprovedHookPlan`.)
//!
//! `ctx.repo` is the invoking worktree — except `wt step commit --branch <b>`
//! and `wt -C <path>` re-root the whole command (the commit, its hooks, and
//! `ctx.repo` is the invoking worktree — except `wt step commit --branch <b>`,
//! `wt merge --branch <b>`, and `wt -C <path>` re-root the whole command (the commit, its hooks, and
//! `ctx.repo` are all `<b>`), so "the invoking worktree" follows them.
//!
//! A present-but-malformed config aborts the operation rather than silently
Expand Down
Loading
Loading