A simple wrapper around git worktree operations, create, switch, and delete. There is some assumed workflow within this plugin, but pull requests are welcomed to fix that).
There are a few known issues. I'll try to be actively filing them in the issues. If you experience something and its not an issue, feel free to make an issue! Even if its a dupe I am just happy for the contribution.
Requires NeoVim 0.5+
First, install the plugin the usual way you prefer.
Plug 'ThePrimeagen/git-worktree.nvim'
Next, re-source your vimrc
/init.vim
and execute PlugInstall
to ensure you have the plugin
installed.
This repository does work best with a bare repo. To clone a bare repo, do the following.
git clone --bare <upstream>
If you do not use a bare repo, using telescope create command will be more helpful in the process of creating a branch.
If the upstream is not setup correctly when trying to pull or push, make sure the following command returns what is shown below. This seems to happen with the gitHub cli.
git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
if it does not run the following
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
update_on_change
: Updates the current buffer to point to the new work tree if
the file is found in the new project. Otherwise, it will open up :Ex
at the
worktree root.
clearjumps_on_change
: Every time you switch branches, your jumplist will be
cleared so that you don't accidentally go backward 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,
})
Three primary functions should cover 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!