Summary of "Git's Best And Most Unknown Feature"
Core problem with traditional Git workflows
When you need to “pivot” mid-work (for example, switching to a production bug or an urgent request), a common approach is:
- Stash or commit your current changes
- Switch branches
- Later unstash / undo the previous work
The speaker notes this process is error-prone and annoying, including forgetting details like an appropriate commit message (e.g., “squash me later”), which can confuse teammates.
What Git worktrees are (main concept)
Git worktrees let you check out multiple commits at the same time.
Instead of the usual model—where a clone has one working directory tied to a single branch/commit—each worktree is:
- A separate folder
- Linked to a specific commit/branch
This isolates branch state, so switching is far less chaotic than stash/commit gymnastics.
Why worktrees are useful
Worktrees enable workflows where you can keep multiple branches checked out simultaneously, such as:
- master
- feature branches
- a hotfix branch
Each in its own directory, without repeatedly stashing/unstashing. The speaker emphasizes that worktrees “fixed” their workflow and felt “mind-blowing,” even though the feature is mature and widely known.
How it works (example commands)
Conventional workflow (stash/commit + switch)
Typically, you’d:
- Run
git clone - Start on master
- Stash/commit your changes before changing branches
Worktree workflow (git worktree)
Instead of switching a single working directory back and forth, you add additional worktrees.
Example operations mentioned:
git worktree add master ...(adds a worktree for the latest commit ofmaster)git worktree add readme ...git worktree add foobar_baz ...
Key behavior:
- Each folder corresponds to a different commit.
- Changes made in one worktree do not appear in the others.
Removing worktrees
Removing worktrees is supported with:
git worktree remove ...
The speaker cautions that you should use remove carefully (including --force when necessary).
Productivity tooling built around worktrees
The speaker built a workflow around worktrees with Neovim plugins.
Neovim/plugin workflow: “git worktree”
They created a Neovim plugin workflow to:
- Wrap
git worktreecommands (faster than manualcdand repeated typing) - Provide a status line showing which branch/worktree you’re editing (helps prevent editing the wrong code)
Telescope integration
They also built a Telescope plugin integration to make switching/creating worktrees easier via an interactive UI.
Demonstration details (plugin behavior)
In the demo, the plugin behavior includes:
- Creating a new worktree automatically moves the editor context into the correct worktree directory.
- Switching branches swaps the edited files so the editor shows the correct version for that worktree.
- If a file exists in one worktree but not another, switching back updates the buffer accordingly—used as evidence that worktrees truly isolate states.
Handling submodules / extra setup automation
In a large C++ project with submodules, the speaker often forgets to update submodules when creating a new worktree, leading to configuration failures and wasted debugging time.
Their git worktree plugin supports hooks/events to automate this:
- On worktree create / switch / delete
- It can trigger actions such as running submodule updates automatically
Example automation mentioned:
- When creating a worktree for a specific repository (described as a “Netflix television device repository”), the plugin runs submodule updates so the user doesn’t have to remember.
Call to action / takeaway
The speaker’s takeaway is to use worktrees because you still get normal Git operations (commit/push/pull) while each branch has its own folder—reducing mental overhead.
They recommend:
- Checking out worktrees
- Using plugin integrations such as:
- Telescope for interactive switching/creation
- a status line
- hook automation (e.g., submodule updates)
Main speakers / sources
- “primetime” — speaker/author of the video; mentions “everything’s made live on twitch” and their Discord community.
Category
Technology
Share this summary
Is the summary off?
If you think the summary is inaccurate, you can reprocess it with the latest model.