Skip to content

Worktree-aware lazygit: sync cwd and buffers#174

Open
romek-codes wants to merge 2 commits into
kdheepak:mainfrom
romek-codes:feat/lazygit-worktree-switch
Open

Worktree-aware lazygit: sync cwd and buffers#174
romek-codes wants to merge 2 commits into
kdheepak:mainfrom
romek-codes:feat/lazygit-worktree-switch

Conversation

@romek-codes

@romek-codes romek-codes commented Mar 29, 2026

Copy link
Copy Markdown
  • Adds optional worktree-aware sync when exiting lazygit: updates cwd and remaps open buffers by relative path.
  • Uses lazygit’s LAZYGIT_NEW_DIR_FILE to detect when a worktree switch occurred.
  • Cleans up stale buffers and preserves modified ones with a warning.
  • Adds config flag g:lazygit_worktree_switch (default off) and documents it.

Closes #137

Add optional worktree-aware syncing when lazygit changes worktrees.
When enabled, it captures open buffers/windows, opens matching files in
the new worktree, updates cwd and window-local dirs, and preserves any
modified buffers with a warning to avoid data loss.
@romek-codes romek-codes changed the title Worktree-aware lazygit: sync cwd and buffers (#137) Worktree-aware lazygit: sync cwd and buffers Mar 29, 2026
  - normalize paths with realpath/resolve to match symlinked roots
  - run worktree sync even on non-zero lazygit exit
  - map Oil root directory buffers to the new worktree
  - restore global cwd updates during sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switching to selected worktree directory

1 participant