docs: Document Git worktrees (#55119)
- Document Git worktrees as a general Git workflow in the Git docs - Add cross-links from AI, tasks, worktree trust, and remote development docs - Include the `git::Worktree` action in the Git action reference The main docs gap was that worktrees were mostly framed as an AI isolation feature, while Zed implements them as a general Git workflow through the title bar worktree picker. Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - N/A --------- Co-authored-by: Danilo Leal <daniloleal09@gmail.com> Co-authored-by: Danilo Leal <67129314+danilo-leal@users.noreply.github.com>
This commit is contained in:
1 parent
fc69edbf5a
commit
ac6dd695fb
5 files changed
+39
-2
No files matched your search
@@ -63,7 +63,7 @@ A single project can contain multiple folders (a multi-root folder project). Age
|
||||
|
||||
## Worktree Isolation {#worktree-isolation}
|
||||
|
||||
If two threads might edit the same files, start one in a new Git worktree to give it an isolated checkout.
|
||||
If two threads might edit the same files, start one in a new [Git worktree](../git.md#git-worktrees) to give it an isolated checkout.
|
||||
|
||||
Worktrees are managed from the title bar. Click the worktree picker (to the right of the project picker) to switch between existing worktrees or create a new one. New worktrees are created in a detached HEAD state, so you won't accidentally share a branch between worktrees.
|
||||
|
||||
|
||||
@@ -168,12 +168,43 @@ Find more information about setting the `preferred-line-length` in the [Configur
|
||||
|
||||
Create a new branch using {#action git::Branch} or switch to an existing branch using {#action git::Switch} or {#action git::CheckoutBranch}.
|
||||
|
||||
When you are working in a [Git worktree](#git-worktrees), use the branch picker after switching to the worktree to create or check out the branch you want to use there.
|
||||
|
||||
### Deleting Branches
|
||||
|
||||
To delete a branch, open the branch switcher with {#action git::Switch}, find the branch you want to delete, and use the delete option. Zed will confirm before deleting to prevent accidental data loss.
|
||||
|
||||
> **Note:** You cannot delete the branch you currently have checked out. Switch to a different branch first.
|
||||
|
||||
## Git Worktrees
|
||||
|
||||
Git worktrees let you keep multiple checkouts of the same repository on disk at the same time.
|
||||
This is useful when you want to work on more than one branch or task without stashing, rebuilding, or disturbing the files in your main checkout.
|
||||
|
||||
Open the worktree picker from the title bar, next to the project picker, or by running {#action git::Worktree}.
|
||||
From the picker, you can:
|
||||
|
||||
- Create a new linked worktree either from the current branch or default branch
|
||||
- Type a name to create a named worktree or let Zed automatically pick one for you
|
||||
- Switch the current workspace to an existing worktree
|
||||
- Open an existing worktree in a new window
|
||||
- Delete linked worktrees that are not currently open in the project
|
||||
|
||||
New worktrees are created in detached HEAD state.
|
||||
After switching to the new worktree, use the branch picker next to the worktree picker to create a new branch or check out an existing, unused branch.
|
||||
This keeps Zed from accidentally checking out the same branch in multiple worktrees.
|
||||
|
||||
The directory used for new worktrees is controlled by the `git.worktree_directory` setting.
|
||||
By default, Zed creates worktrees under `../worktrees` relative to the repository's working directory.
|
||||
|
||||
See [All Settings](./reference/all-settings.md#git-worktree-directory) for examples.
|
||||
|
||||
If your project contains multiple Git repositories (i.e., multi-root folders), Zed creates a linked worktree for each repository when creating a new worktree from the picker.
|
||||
Non-Git folders in the same project are included in the new workspace as-is.
|
||||
|
||||
To run setup steps after Zed creates a linked worktree, use the [`create_worktree` task hook](./tasks.md#hooks).
|
||||
For agent-specific workflows, see [Worktree Isolation](./ai/parallel-agents.md#worktree-isolation).
|
||||
|
||||
## Merge Conflicts
|
||||
|
||||
When you encounter merge conflicts after a merge, rebase, or pull, Zed highlights the conflicting regions in your files and displays resolution buttons above each conflict.
|
||||
@@ -337,6 +368,7 @@ When viewing files with changes, Zed displays diff hunks that can be expanded or
|
||||
| {#action git::Branch} | {#kb git::Branch} |
|
||||
| {#action git::Switch} | {#kb git::Switch} |
|
||||
| {#action git::CheckoutBranch} | {#kb git::CheckoutBranch} |
|
||||
| {#action git::Worktree} | {#kb git::Worktree} |
|
||||
| {#action git::Blame} | {#kb git::Blame} |
|
||||
| {#action git::StashAll} | {#kb git::StashAll} |
|
||||
| {#action git::StashPop} | {#kb git::StashPop} |
|
||||
|
||||
@@ -262,6 +262,9 @@ Note that we deliberately disallow some options (for example `-t` or `-T`) that
|
||||
|
||||
- [Running & Testing](./running-testing.md): Run tasks, terminal commands, and
|
||||
debugger sessions while you work remotely.
|
||||
- [Git Worktrees](./git.md#git-worktrees): Create and switch between linked
|
||||
Git worktrees. Zed supports the worktree picker in remote projects when the
|
||||
remote connection is active.
|
||||
- [Configuring Zed](./configuring-zed.md): Manage shared and project settings,
|
||||
including `.zed/settings.json`.
|
||||
- [Agent Panel](./ai/agent-panel.md): Use AI workflows in remote projects.
|
||||
|
||||
+1
-1
@@ -236,7 +236,7 @@ In addition to being spawned manually, tasks can be configured to run automatica
|
||||
|
||||
The following hooks are currently supported:
|
||||
|
||||
- `create_worktree` — runs after Zed creates a new linked Git worktree, either directly through the CLI or through the UI with the worktree modal. The task is spawned with `ZED_WORKTREE_ROOT` pointing at the newly created worktree and `ZED_MAIN_GIT_WORKTREE` pointing at the original repository's working directory, which makes these hooks well-suited to copying untracked files (such as `.env` files) or running per-worktree setup commands.
|
||||
- `create_worktree` — runs after Zed creates a new linked Git worktree, either directly through the CLI or from the [worktree picker](./git.md#git-worktrees). The task is spawned with `ZED_WORKTREE_ROOT` pointing at the newly created worktree and `ZED_MAIN_GIT_WORKTREE` pointing at the original repository's working directory, which makes these hooks well-suited to copying untracked files (such as `.env` files) or running per-worktree setup commands.
|
||||
|
||||
Hook tasks are resolved from the same global and worktree-local `tasks.json` files as manually spawned tasks, and multiple tasks may register for the same hook; they all run when the hook fires. A hook task still benefits from the usual task configuration fields — `cwd`, `env`, `reveal`, `hide`, and so on — so you can control how much of the terminal UI is shown while it runs.
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ description: "Configure which folders Zed trusts for running code and extensions
|
||||
A worktree in Zed is either a directory or a single file that Zed opens as a standalone "project".
|
||||
Zed opens a worktree each time you run `zed some/path`, drag a file or directory into Zed, or open your user settings file.
|
||||
|
||||
> Note: This is broader than a [Git worktree](./git.md#git-worktrees). A Git worktree is a linked checkout managed by Git; Zed's trust model applies to every opened file or folder root, including Git worktrees.
|
||||
|
||||
Every worktree opened may contain a `.zed/settings.json` file with extra configuration options that may require installing and spawning language servers or MCP servers.
|
||||
To let users choose based on their own threat model and risk tolerance, all worktrees start in Restricted Mode. Restricted Mode prevents downloading and running related items from `.zed/settings.json`. Until a worktree is trusted, Zed does not run related untrusted actions and waits for user confirmation. This gives users a chance to review project settings, MCP servers, and language servers.
|
||||
|
||||
|
||||
Reference in new issue
Block a user