A simple wrapper around git worktree operations, create, switch, and delete. There is definitely some assumed work flow within this plugin (prs wanted to fix that).
Requires NeoVim 0.5+
First, install the plugin the usual way you prefer.
Plug 'ThePrimeagen/git-worktree.nvim'
Resource your vimrc and execute PlugInstall
to ensure you have the plugin
installed.
update_on_change
: Updates the current buffer to point to the new work tree if
the file is found in the new project, else it will open up :Ex
at the
worktree root
clearjumps_on_change
: Everytime you switch branches, your jumplist will be
cleared so that you don't accidentally go backwards to a different branch and
edit the wrong files.
require("git-worktree").setup({
update_on_change = <boolean> -- default: true,
clearjumps_on_change = <boolean> -- default: true,
})
There are three primary functions that should be your day to day.
-- Creates a worktree. Requires the branch name and the upstream
-- Example:
:lua require("git-worktree").create_worktree("feat-69", "upstream/master")
-- switches to an existing worktree. Requires the branch name
-- Example:
:lua require("git-worktree").switch_worktree("feat-69")
-- deletes to an existing worktree. Requires the branch name
-- Example:
:lua require("git-worktree").delete_worktree("feat-69")
Add the following to your vimrc to load the telescope extension
require("telescope").load_extension("git_worktree")
To bring up the telescope window listing your workspaces run the following
:lua require('telescope').extensions.git_worktree.git_worktrees()
-- <Enter> - switches to that worktree
-- <c-d> - deletes that worktree
-- <c-D> - force deletes that worktree
Yes! The best part about git-worktree is that it emits information so that you can act on it.
local Worktree = require("git-worktree")
-- op = "switch", "create", "delete"
-- path = branch in which was swapped too
-- upstream = only present on create, upstream of create operation
Worktree.on_tree_update(function(op, path, upstream)
end)
This means that you can use harpoon or other plugins to perform follow up operations that will help in turbo charging your development experience!
all plugins are made live on Twitch with love and fury. Come and join!