Skip to content

Jimmie-Rissanen/git-worktree.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git-worktree.nvim


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).

Warning

Requires NeoVim 0.5+

Getting Started

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.

Setup

Repository

Currently, this plugin assumes that you have a bare repository setup for your worktrees. Before creating them, be sure you to clone a bare version of your repository as shown below. In the future, this will be handled automatically by the plugin.

git clone --bare <upstream>

Troubleshooting

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/*"

Options

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: Every time 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,
})

Usage

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")

Telescope

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

Hooks!

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!

Made with fury

all plugins are made live on Twitch with love and fury. Come and join!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 77.4%
  • Shell 18.7%
  • Perl 3.6%
  • Other 0.3%