Academy → Operating HermesOfficial documentation · Arabic guidance

Git Worktrees

العمل على فروع متوازية بـGit Worktrees

Intermediate5 min readLesson 101 question✓ 2026-08-18
Before you read

What this page is, and what it holds.

This page covers Git Worktrees. You will use hermes chat and hermes git worktree add here; about 5 minutes to read. Very long sessions lose their own beginning and cost more. Start a new one per task.

8sections
8code examples
0tables
2commands
885source words
The official one-line description

Run multiple Hermes agents safely on the same repository using git worktrees and isolated checkouts

What you will be able to do

Outcomes taken from this page, not a template.

  • Understand what الجلسة is and when you need it.
  • Run hermes chat and hermes git worktree add and understand what happens next.
  • Know the common mistake before you hit it.
Identifiers you will meet

Exactly as they appear in Hermes.

Commands
  • hermes chat
  • hermes git worktree add
Page map

Jump to the part you need.

  1. 01Why Use Worktrees with Hermes?
  2. 02Quick Start: Creating a Worktree
  3. 03Running Multiple Agents in Parallel
  4. 04Cleaning Up Worktrees Safely
  5. 05Best Practices
  6. 06Using `hermes -w` (Automatic Worktree Mode)
  7. 07Putting It All Together
  8. 08Developing the UI surfaces across worktrees
The full official page

Nothing summarised away.

The documentation body below is reproduced from the official source so commands and identifiers stay exact. Each section carries a short note describing what it contains.

Hermes Agent is often used on large, long‑lived repositories. When you want to:

  • Run multiple agents in parallel on the same project, or
  • Keep experimental refactors isolated from your main branch,

Git worktrees are the safest way to give each agent its own checkout without duplicating the entire repository.

This page shows how to combine worktrees with Hermes so each session has a clean, isolated working directory.

Why Use Worktrees with Hermes?

Commands you type in a terminal. Understand what one does before copying it. Commands here: hermes chat.

Hermes treats the current working directory as the project root:

  • CLI: the directory where you run hermes or hermes chat
  • Messaging gateways: the directory set by terminal.cwd in ~/.hermes/config.yaml

If you run multiple agents in the same checkout, their changes can interfere with each other:

  • One agent may delete or rewrite files the other is using.
  • It becomes harder to understand which changes belong to which experiment.

With worktrees, each agent gets:

  • Its own branch and working directory
  • Its own Checkpoint Manager history for /rollback

See also: Checkpoints and /rollback.

Quick Start: Creating a Worktree

Ordered, practical steps. Run one and confirm it worked before moving on.

From inside a session: /worktree new

The fastest path (inspired by Copilot CLI's /worktree new): from an interactive CLI session, run

Text1 line
/worktree new my-experiment

Hermes creates .worktrees/my-experiment/ inside the repo (branch hermes/my-experiment, based on the freshly-fetched remote tip unless worktree_sync: false), and retargets the session's terminal and file tools into it — no restart needed. Omit the name to get a random hermes-<id> tree. /worktree alone shows the active tree; /worktree list lists all of them. On exit the tree is kept only if it has unpushed commits, exactly like hermes -w.

Manually with git

From your main repository (containing .git/), create a new worktree for a feature branch:

Shell5 lines
# From the main repo root
cd /path/to/your/repo

# Create a new branch and worktree in ../repo-feature
git worktree add ../repo-feature feature/hermes-experiment

This creates:

  • A new directory: ../repo-feature
  • A new branch: feature/hermes-experiment checked out in that directory

Now you can cd into the new worktree and run Hermes there:

Shell4 lines
cd ../repo-feature

# Start Hermes in the worktree
hermes

Hermes will:

  • See ../repo-feature as the project root.
  • Use that directory for context files, code edits, and tools.
  • Use a separate checkpoint history for /rollback scoped to this worktree.

Running Multiple Agents in Parallel

Commands you type in a terminal. Understand what one does before copying it. Commands here: hermes git worktree add.

You can create multiple worktrees, each with its own branch:

Shell4 lines
cd /path/to/your/repo

git worktree add ../repo-experiment-a feature/hermes-a
git worktree add ../repo-experiment-b feature/hermes-b

In separate terminals:

Shell7 lines
# Terminal 1
cd ../repo-experiment-a
hermes

# Terminal 2
cd ../repo-experiment-b
hermes

Each Hermes process:

  • Works on its own branch (feature/hermes-a vs feature/hermes-b).
  • Writes checkpoints under a different shadow repo hash (derived from the worktree path).
  • Can use /rollback independently without affecting the other.

This is especially useful when:

  • Running batch refactors.
  • Trying different approaches to the same task.
  • Pairing CLI + gateway sessions against the same upstream repo.

Cleaning Up Worktrees Safely

Explains the idea itself. Read it slowly; the later sections build on it.

When you are done with an experiment:

  1. Decide whether to keep or discard the work.
  2. If you want to keep it:
  3. Merge the branch into your main branch as usual.
  4. Remove the worktree:
Shell4 lines
cd /path/to/your/repo

# Remove the worktree directory and its reference
git worktree remove ../repo-feature

Notes:

  • git worktree remove will refuse to remove a worktree with uncommitted changes unless you force it.
  • Removing a worktree does not automatically delete the branch; you can delete or keep the branch using normal git branch commands.
  • Hermes checkpoint data under ~/.hermes/checkpoints/ is not automatically pruned when you remove a worktree, but it is usually very small.

Best Practices

Explains the idea itself. Read it slowly; the later sections build on it.

  • One worktree per Hermes experiment
  • Create a dedicated branch/worktree for each substantial change.
  • This keeps diffs focused and PRs small and reviewable.
  • Name branches after the experiment
  • e.g. feature/hermes-checkpoints-docs, feature/hermes-refactor-tests.
  • Commit frequently
  • Use git commits for high‑level milestones.
  • Use checkpoints and /rollback as a safety net for tool‑driven edits in between.
  • Avoid running Hermes from the bare repo root when using worktrees
  • Prefer the worktree directories instead, so each agent has a clear scope.

Using `hermes -w` (Automatic Worktree Mode)

Explains the idea itself. Read it slowly; the later sections build on it.

Hermes has a built‑in -w flag that automatically creates a disposable git worktree with its own branch. You don't need to set up worktrees manually — just cd into your repo and run:

Shell2 lines
cd /path/to/your/repo
hermes -w

Hermes will:

  • Create a temporary worktree under .worktrees/ inside your repo.
  • Check out an isolated branch (e.g. hermes/hermes-<hash>).
  • Run the full CLI session inside that worktree.

This is the easiest way to get worktree isolation. You can also combine it with a single query:

Shell1 line
hermes -w -z "Fix issue #123"

For parallel agents, open multiple terminals and run hermes -w in each — every invocation gets its own worktree and branch automatically.

Putting It All Together

Explains the idea itself. Read it slowly; the later sections build on it.

  • Use git worktrees to give each Hermes session its own clean checkout.
  • Use branches to capture the high‑level history of your experiments.
  • Use checkpoints + /rollback to recover from mistakes inside each worktree.

This combination gives you:

  • Strong guarantees that different agents and experiments do not step on each other.
  • Fast iteration cycles with easy recovery from bad edits.
  • Clean, reviewable pull requests.

Developing the UI surfaces across worktrees

Explains the idea itself. Read it slowly; the later sections build on it.

The TypeScript surfaces (ui-tui/, apps/desktop/) each need a node_modules, which a fresh npm ci per worktree duplicates across every branch. If you hack on the TUI or desktop app from multiple worktrees, see TUI & Desktop from Worktrees for the htui / hgui helpers that share one install by symlink.

Knowledge check

1 question answered by this page alone.

Every option is a real identifier from the Hermes documentation. The wrong ones are real too, just from other pages.

1. Which of these headings does not appear in this lesson?