Skip to content

Conversation

@AlvaroParker
Copy link
Contributor

@AlvaroParker AlvaroParker commented Sep 23, 2025

Related discussions #26084

Worktree creations are implemented similar to how branch creations are handled on the branch picker (the user types a new name that's not on the list and a new entry option appears to create a new branch with that name).

2025-09-23.17-12-34.mp4

With this picker you have a few workflows:

  • Open the picker and type the name of a branch that's checked out on an existing worktree:
    • Press enter to open the worktree on a new window
    • Press ctrl-enter to open the worktree and replace the current window
  • Open the picker and type the name of a new branch or an existing one that's not checked out in another worktree:
    • Press enter to create the worktree and open in a new window. If the branch doesn't exists, we will create a new one based on the branch you have currently checked out. If the branch does exists then we create a worktree with that branch checked out.
    • Press ctrl-enter to do everything on the previous point but instead, replace the current window with the new worktre.
  • Open the picker and type the name of a new branch or an existing one that's not checked out in another worktree:
    • If a default branch is detected on the repo, you can create a new worktree based on that branch by pressing ctrl-enter or ctrl-shift-enter. The first one will open a new window and the last one will replace the current one.

Note: If you preffer to not use the system prompt for choosing a directory, you can set "use_system_path_prompts": false in zed settings.

Release Notes:

  • Added git worktree picker to open a git worktree on a new window or replace the current one
  • Added git worktree creation action

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Sep 23, 2025
@AlvaroParker AlvaroParker marked this pull request as ready for review September 24, 2025 13:29
@nwalke
Copy link

nwalke commented Sep 26, 2025

Any chance of this being a zed extension rather than integrated straight to core? I only ask because I think that would be the faster way to get this and I really want to use it :)

@AlvaroParker
Copy link
Contributor Author

Hey @nwalke currently zed does not support that kind of extensions. And even if it does, I don't think it would be a good idea to move this to an extension. Zed already has git support so improving that support is the right choice imo.

I don't think it should take too long for a zed team member to review this (and hopefully, aprove it), of course you can always compile this branch from source and use it (at your own risk).

@EpicEric
Copy link

Oh nice! I was trying to make an extension myself but I ran into the same issues, and then I stumbled upon this pull request.

My only suggestion is adding git worktree remove functionality as well.

@AlvaroParker
Copy link
Contributor Author

AlvaroParker commented Sep 28, 2025

I'll probably add worktree remove on another PR just because I'm not sure about the UI/UX for that functionality. For now, I think this PR is ready to go.

@AlvaroParker AlvaroParker force-pushed the worktree-picker branch 3 times, most recently from 75d8e1d to 6fbbd6c Compare October 3, 2025 02:16
@AlvaroParker AlvaroParker force-pushed the worktree-picker branch 3 times, most recently from 5f91c94 to da9a09c Compare October 14, 2025 20:36
Copy link
Member

@cole-miller cole-miller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AlvaroParker, nice work and sorry for the delay in reviewing--this looks generally good, the only blocker I've noticed is the handling of opening worktrees in remote projects.

@cole-miller
Copy link
Member

Thanks! In the latest revision it seems like opening remote worktrees isn't quite working--when I select a worktree from the picker I get a window with the original remote project, not a project for the selected worktree. Based on how open_remote_project_with_existing_connection is used elsewhere, I think we need to construct a remote project to pass into it using Project::remote, instead of using a local project.

@AlvaroParker
Copy link
Contributor Author

I was hoping in reusing the connection of the active projects when on remote, but when I try creating a new remote Project from the existing connection I hit a few panics on proto_client.rs which indicate we can't have more than 1 project with the same underlying connection. I went for the second best approach, that is, opening a new connection when switching between worktrees.

Copy link
Member

@cole-miller cole-miller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, nice work on this! Just merging main manually to confirm there aren't any semantic merge conflicts here.

@cole-miller cole-miller merged commit e5660d2 into zed-industries:main Nov 4, 2025
24 checks passed
P1n3appl3 pushed a commit to bnjjj/zed that referenced this pull request Nov 4, 2025
Related discussions zed-industries#26084 

Worktree creations are implemented similar to how branch creations are
handled on the branch picker (the user types a new name that's not on
the list and a new entry option appears to create a new branch with that
name).


https://github.com/user-attachments/assets/39e58983-740c-4a91-be88-57ef95aed85b

With this picker you have a few workflows: 

- Open the picker and type the name of a branch that's checked out on an
existing worktree:
    - Press enter to open the worktree on a new window
- Press ctrl-enter to open the worktree and replace the current window
- Open the picker and type the name of a new branch or an existing one
that's not checked out in another worktree:
- Press enter to create the worktree and open in a new window. If the
branch doesn't exists, we will create a new one based on the branch you
have currently checked out. If the branch does exists then we create a
worktree with that branch checked out.
- Press ctrl-enter to do everything on the previous point but instead,
replace the current window with the new worktre.
- Open the picker and type the name of a new branch or an existing one
that's not checked out in another worktree:
- If a default branch is detected on the repo, you can create a new
worktree based on that branch by pressing ctrl-enter or
ctrl-shift-enter. The first one will open a new window and the last one
will replace the current one.


Note: If you preffer to not use the system prompt for choosing a
directory, you can set `"use_system_path_prompts": false` in zed
settings.

Release Notes:

- Added git worktree picker to open a git worktree on a new window or
replace the current one
- Added git worktree creation action

---------

Co-authored-by: Cole Miller <[email protected]>
@AlvaroParker
Copy link
Contributor Author

Awesome! One thing I've notice just now (that I didn't catch), is that when the following happens:

  • A branch bar is currently checked out
  • A new branch foo is created based off bar
  • The user tries to create a new worktree with the name foo based off main

The worktree fails to create because there's already a branch foo based off bar

Should we handle this edge case? Or is the error ok to have? Since the user is trying to create a branch that already exists but based off another branch.

This doesn't happens if the user creates a worktree foo based off bar. If this is the case, the worktree correctly checks out the already created foo branch in the new worktree.

@xtrasmal
Copy link
Contributor

xtrasmal commented Nov 5, 2025

Awesome, thanks @AlvaroParker

@sundaycrafts
Copy link

OMG THIS IS AWESOME!!!!! So cool

tomatitito pushed a commit to tomatitito/zed that referenced this pull request Nov 7, 2025
Related discussions zed-industries#26084 

Worktree creations are implemented similar to how branch creations are
handled on the branch picker (the user types a new name that's not on
the list and a new entry option appears to create a new branch with that
name).


https://github.com/user-attachments/assets/39e58983-740c-4a91-be88-57ef95aed85b

With this picker you have a few workflows: 

- Open the picker and type the name of a branch that's checked out on an
existing worktree:
    - Press enter to open the worktree on a new window
- Press ctrl-enter to open the worktree and replace the current window
- Open the picker and type the name of a new branch or an existing one
that's not checked out in another worktree:
- Press enter to create the worktree and open in a new window. If the
branch doesn't exists, we will create a new one based on the branch you
have currently checked out. If the branch does exists then we create a
worktree with that branch checked out.
- Press ctrl-enter to do everything on the previous point but instead,
replace the current window with the new worktre.
- Open the picker and type the name of a new branch or an existing one
that's not checked out in another worktree:
- If a default branch is detected on the repo, you can create a new
worktree based on that branch by pressing ctrl-enter or
ctrl-shift-enter. The first one will open a new window and the last one
will replace the current one.


Note: If you preffer to not use the system prompt for choosing a
directory, you can set `"use_system_path_prompts": false` in zed
settings.

Release Notes:

- Added git worktree picker to open a git worktree on a new window or
replace the current one
- Added git worktree creation action

---------

Co-authored-by: Cole Miller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants