Skip to content

Latest commit

 

History

History
72 lines (51 loc) · 2.32 KB

File metadata and controls

72 lines (51 loc) · 2.32 KB

telescope_worktree.nvim

telescope_worktree is a Telescope extension that searches a Git branch (Remote or local) and creates a new worktreee in the directory specified.

image

The telescope_worktree.nvim extension is excellent for working with feature branches, where changing the branch requires a build or compile to work with the changes. It leverages git worktrees to work on multiple branches simultaneously and independently.

The extension uses this command to create a git-worktree from the remote branch

Command used for existing remote branch

git worktree add --track -b <branch> <path> refs/remotes/<remote>/<branch>

Command used for new branch based on current branch in local (you can manually set the remote while pushing)

git worktree add -b <branch> <path>

Installation

You can install these plugin using your favorite vim package manager, e.g. vim-plug and lazy.

lazy:

{ 'katkodeorg/telescope_worktree.nvim' },

vim-plug

Plug 'https://github.com/katkodeorg/telescope_worktree.nvim'

Usage

Activate the telescope_worktree.nvim extension by adding

{
    'nvim-telescope/telescope.nvim',
    dependencies = {
--     ...
      { 'katkodeorg/telescope_worktree.nvim' },
--     ...
    },
--  ...
}

Somewhere after your require('telescope').setup() call add:

pcall(require('telescope').load_extension, 'telescope_worktree')

Example to bind it to <leader>wt use:

local extensions = require('telescope').extensions
vim.keymap.set('n', '<leader>wt', function()
  extensions.telescope_worktree.create_worktree()
end, { desc = '[W]ork tree [C]reate' })

Open telescope to choose from the existing remote branches. If none with the given name exist, it will attempt to create a new local branch from the name provided.

If you try to create a git worktree for an already checked out branch in your local, it will fail. To checkout the branch in a new worktree, save your changes and delete the local branch.