Skip to content

Instantly share code, notes, and snippets.

@benozol
Created April 6, 2020 21:24
Show Gist options
  • Save benozol/3ed34c712fc750b75dc4da73a51566b3 to your computer and use it in GitHub Desktop.
Save benozol/3ed34c712fc750b75dc4da73a51566b3 to your computer and use it in GitHub Desktop.
;; Open the file in the current buffer in another git worktree
(defun my/magit-open-file-in-worktree ()
(interactive)
(flet ((worktrees ()
(mapcar
(lambda (x) (cons (nth 3 x) (nth 0 x)))
(magit-list-worktrees)))
(open-buffer (repo-path)
(let* ((file-path (file-relative-name buffer-file-name (magit-toplevel)))
(filename (concat (file-name-as-directory repo-path) file-path)))
(find-file filename))))
(helm :sources '((name . "Git worktrees")
(candidates . worktrees)
(action . open-buffer)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment