move-to-worktree

Move the checked-out git branch into a .worktrees directory.

Updated Sep 9, 2024
One-click install
npx skills add https://github.com/axel-kaliff/dotfiles --skill move-to-worktree
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: move-to-worktree
Source: https://github.com/axel-kaliff/dotfiles/tree/main/claude/.claude/skills/move-to-worktree
Command: npx skills add https://github.com/axel-kaliff/dotfiles --skill move-to-worktree

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Keeps the project root checked out on master while moving feature work into isolated worktrees, preventing accidental development in the repository root and simplifying branch isolation.

Core Features & Use Cases

  • Move checked-out branch into .worktrees: Detaches HEAD, creates a worktree for the existing branch under .worktrees, and checks out master in the project root.
  • Safety checks and repository hygiene: Refuses to run when on master/main, when HEAD is detached, when there are uncommitted changes, or when the target path already exists, and ensures .worktrees is added to .gitignore.
  • Nested path support: Accepts a nested subdirectory path (e.g., logging/refactor-logging) and creates parent directories automatically for organized worktree placement.

Quick Start

Move the current branch into a .worktrees subdirectory named logging/refactor-logging so the project root remains on master.

Frequently Asked Questions about move-to-worktree

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I keep my git project root on master while working on a feature branch?

Git worktrees let you isolate feature branches into a .worktrees directory, detaching HEAD to move the checked-out branch out of the project root and restoring master. This prevents accidental development in the repository root.

Can I create git worktrees with nested subdirectory paths for organized branch isolation?

Yes, you can supply a nested subdirectory path like logging/refactor-logging when creating git worktrees, and parent directories are created automatically so the feature branch runs in an organized separate worktree.

What happens to uncommitted changes when moving a branch into a git worktree?

The process refuses to run when there are uncommitted changes, ensuring safety before detaching HEAD and creating the worktree. You must commit or stash changes first to proceed with branch isolation.

Does git worktree creation add the .worktrees directory to .gitignore automatically?

Yes, creating a worktree under .worktrees adds that directory to .gitignore if needed, keeping repository hygiene intact so the isolated feature branch directories are excluded from git tracking.

When should I not use a git worktree to isolate a feature branch?

You should not use this approach when already on master or main, when HEAD is detached, or when the target worktree path already exists. The process refuses to run in these states to prevent overwriting or conflicts.

What is the best way to prevent accidental commits to master in the project root?

Moving feature work into isolated git worktrees under .worktrees keeps the project root checked out on master, preventing accidental development and simplifying branch isolation for safer repository management.