본문으로 건너뛰기
cccskills
무료GitHub에 공개

git-worktree

Create and manage Git worktrees, separate folders for working on different branches. Organize them under a shared project path, move uncommitted or stashed changes between them, copy environment files, and open them in an editor.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

Manage Git worktrees in project-level ../.zcf/project-name/ directory with smart defaults, IDE integration and content migration

설치 방법 보기

이럴 때 유용합니다

  • Create separate folders for parallel branch work
  • Move uncommitted changes to another worktree
  • Apply stashed changes to another worktree
  • List and remove unused worktrees

포함된 파일(1)

  • SKILL.md9.9 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Claude Command: Git Worktree

Manage Git worktrees with smart defaults, IDE integration and content migration in structured ../.zcf/project-name/ paths.

Execute commands directly and provide concise results.


Usage

# Basic operations
/git-worktree add <path>                           # create new branch named <path> from main/master
/git-worktree add <path> -b <branch>               # create new branch with specified name
/git-worktree add <path> -o                        # create and open directly in IDE
/git-worktree list                                 # show all worktree status
/git-worktree remove <path>                        # remove specified worktree
/git-worktree prune                                # clean invalid worktree references

# Content migration
/git-worktree migrate <target> --from <source>     # migrate uncommitted content
/git-worktree migrate <target> --stash             # migrate stash content

Options

OptionDescription
add [<path>]Add new worktree in ../.zcf/project-name/<path>
migrate <target>Migrate content to specified worktree
listList all worktrees and their status
remove <path>Remove worktree at specified path
pruneClean invalid worktree references
-b <branch>Create new branch and checkout to worktree
-o, --openOpen directly in IDE after creation (skip prompt)
--from <source>Specify migration source path (migrate only)
--stashMigrate current stash content (migrate only)
--trackSet new branch to track corresponding remote branch
--guess-remoteAuto guess remote branch for tracking
--detachCreate detached HEAD worktree
--checkoutCheckout immediately after creation (default behavior)
--lockLock worktree after creation

What This Command Does

  1. Environment Check

    • Verify Git repository using git rev-parse --is-inside-work-tree
    • Detect whether in main repo or existing worktree for smart path calculation
  2. Smart Path Management

    • Auto-calculate project name from main repository path using worktree detection
    • Create worktrees in structured ../.zcf/project-name/<path> directory
    • Handle both main repo and worktree execution contexts correctly
# Core path calculation logic for worktree detection
get_main_repo_path() {
  local git_common_dir=$(git rev-parse --git-common-dir 2>/dev/null)
  local current_toplevel=$(git rev-parse --show-toplevel 2>/dev/null)

  # Check if in worktree
  if [[ "$git_common_dir" != "$current_toplevel/.git" ]]; then
    # In worktree, derive main repo path from git-common-dir
    dirname "$git_common_dir"
  else
    # In main repository
    echo "$current_toplevel"
  fi
}

MAIN_REPO_PATH=$(get_main_repo_path)
PROJECT_NAME=$(basename "$MAIN_REPO_PATH")
WORKTREE_BASE="$MAIN_REPO_PATH/../.zcf/$PROJECT_NAME"

# Always use absolute path to prevent nesting issues
ABSOLUTE_WORKTREE_PATH="$WORKTREE_BASE/<path>"

Critical Fix: Always use absolute paths when creating worktrees from within existing worktrees to prevent path nesting issues like ../.zcf/project/.zcf/project/path.

  1. Worktree Operations

    • add: Create new worktree with smart branch/path defaults
    • list: Display all worktrees with branches and status
    • remove: Safely remove worktree and clean references
    • prune: Clean orphaned worktree records
  2. Smart Defaults

    • Branch creation: When no -b specified, create new branch using path name
    • Base branch: New branches created from main/master branch
    • Path resolution: Use branch name as path when unspecified
    • IDE integration: Auto-detect and prompt for IDE opening
  3. Content Migration

    • Migrate uncommitted changes between worktrees
    • Apply stash content to target worktree
    • Safety checks to prevent conflicts
  4. Safety Features

    • Path conflict prevention: Check for existing directories before creation
    • Branch checkout validation: Ensure branches aren't already in use
    • Absolute path enforcement: Prevent nested .zcf directories when in worktree
    • Auto-cleanup on removal: Clean both directory and git references
    • Clear status reporting: Display worktree locations and branch status
  5. Environment File Handling

    • Auto-detection: Scan .gitignore for environment variable file patterns
    • Smart copying: Copy .env and .env.* files that are listed in .gitignore
    • Exclusion logic: Skip .env.example and other template files
    • Permission preservation: Maintain original file permissions and timestamps
    • User feedback: Provide clear status on copied environment files
# Environment file copying implementation
copy_environment_files() {
    local main_repo="$MAIN_REPO_PATH"
    local target_worktree="$ABSOLUTE_WORKTREE_PATH"
    local gitignore_file="$main_repo/.gitignore"
    
    # Check if .gitignore exists
    if [[ ! -f "$gitignore_file" ]]; then
        return 0
    fi
    
    local copied_count=0
    
    # Detect .env file
    if [[ -f "$main_repo/.env" ]] && grep -q "^\.env$" "$gitignore_file"; then
        cp "$main_repo/.env" "$target_worktree/.env"
        echo "✅ Copied .env"
        ((copied_count++))
    fi
    
    # Detect .env.* pattern files (excluding .env.example)
    for env_file in "$main_repo"/.env.*; do
        if [[ -f "$env_file" ]] && [[ "$(basename "$env_file")" != ".env.example" ]]; then
            local filename=$(basename "$env_file")
            if grep -q "^\.env\.\*$" "$gitignore_file"; then
                cp "$env_file" "$target_worktree/$filename"
                echo "✅ Copied $filename"
                ((copied_count++))
            fi
        fi
    done
    
    if [[ $copied_count -gt 0 ]]; then
        echo "📋 Copied $copied_count environment file(s) from .gitignore"
    fi
}

Enhanced Features

IDE Integration

  • Auto-detection: VS Code → Cursor → WebStorm → Sublime Text → Vim
  • Smart prompting: Ask to open in IDE after worktree creation
  • Direct open: Use -o flag to skip prompt and open immediately
  • Custom configuration: Configurable via git config

Content Migration System

# Migrate uncommitted changes
/git-worktree migrate feature-ui --from main
/git-worktree migrate hotfix --from ../other-worktree

# Migrate stash content
/git-worktree migrate feature-ui --stash

Migration Flow:

  1. Verify source has uncommitted content
  2. Ensure target worktree is clean
  3. Show changes to be migrated
  4. Execute safe migration using git commands
  5. Confirm results and suggest next steps

Examples

# Basic usage
/git-worktree add feature-ui                       # create new branch 'feature-ui' from main/master
/git-worktree add feature-ui -b my-feature         # create new branch 'my-feature' with path 'feature-ui'
/git-worktree add feature-ui -o                    # create and open in IDE directly

# Content migration scenarios
/git-worktree add feature-ui -b feature/new-ui     # create new feature worktree
/git-worktree migrate feature-ui --from main       # migrate uncommitted changes
/git-worktree migrate hotfix --stash               # migrate stash content

# Management operations
/git-worktree list                                 # view all worktrees
/git-worktree remove feature-ui                    # remove unneeded worktree
/git-worktree prune                                # clean invalid references

Example Output:

✅ Worktree created at ../.zcf/project-name/feature-ui
✅ Copied .env
✅ Copied .env.local
📋 Copied 2 environment file(s) from .gitignore
🖥️ Open ../.zcf/project-name/feature-ui in IDE? [y/n]: y
🚀 Opening ../.zcf/project-name/feature-ui in VS Code...

Directory Structure

parent-directory/
├── your-project/            # main project
│   ├── .git/
│   └── src/
└── .zcf/                    # worktree management
    └── your-project/        # project worktrees
        ├── feature-ui/      # feature branch
        ├── hotfix/          # hotfix branch
        └── debug/           # debug worktree

Configuration

IDE Configuration

  • Supports VS Code, Cursor, WebStorm, Sublime Text, Vim
  • Configurable via git config for custom IDEs
  • Auto-detection with priority-based selection

Custom IDE Setup

# Configure custom IDE
git config worktree.ide.custom.sublime "subl %s"
git config worktree.ide.preferred "sublime"

# Control auto-detection
git config worktree.ide.autodetect true  # default

Notes

  • Performance: Worktrees share .git directory, saving disk space
  • Safety: Path conflict prevention and branch checkout validation
  • Migration: Only uncommitted changes; use git cherry-pick for commits
  • IDE requirement: Command-line tools must be in PATH
  • Cross-platform: Supports Windows, macOS, Linux
  • Environment files: Automatically copies environment files listed in .gitignore to new worktrees
  • File exclusions: Template files like .env.example are preserved in main repo only

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

bmad-init

무료

Install or update BMad-Method (V6) in a project after checking existing installations. The skill also fixes a known output-folder issue, updates Git ignore rules, and provides next steps for using the installed workflows.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Set up BMad-Method (V6) for Claude Code
  • Run a quick update on an existing V6 installation
  • Check for an older V4 installation before setup
UfoMiao/zcf6.1천2026년 8월 31일 업데이트

bmad-init

무료

Set up or update BMad-Method V6 in a project, detect older installations, fix a known output folder issue, and adjust Git ignore rules, with guidance on what to do next.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Installing BMad-Method V6 in a project
  • Updating an existing V6 installation
  • Checking for an older V4 installation
UfoMiao/zcf6.1천2026년 8월 31일 업데이트

feat

무료

Turn feature requests into documented plans, revise them through discussion, and carry out implementation with progress tracking. Frontend work includes checking for a UI design and arranging design work when needed.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Turning a feature idea into a development plan
  • Revising a plan after feedback
  • Implementing tasks from an agreed plan
UfoMiao/zcf6.1천2026년 8월 31일 업데이트

feat

무료

Guide new feature work from requirements and planning through revisions and implementation. Create Markdown plans with acceptance criteria, track progress, and ensure frontend tasks have a UI design before development begins.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Turn a feature idea into an implementation plan
  • Revise a plan based on feedback
  • Start implementation from an agreed plan
UfoMiao/zcf6.1천2026년 8월 31일 업데이트

Find merged or inactive Git branches, preview cleanup candidates, and delete selected branches after confirmation. Choose a comparison branch, protect important branches with configurable rules, and optionally include remote branches.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Previewing branch cleanup candidates
  • Removing branches already merged into a release branch
  • Finding branches with no recent commits
UfoMiao/zcf6.1천2026년 8월 31일 업데이트

Find Git branches that have been merged or inactive for a chosen period. Preview cleanup candidates, exclude protected branches, and delete local or remote branches using a selected base branch and confirmation options.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Find merged branches to clean up
  • Review branches with no recent commits
  • Clean up branches merged into a release
UfoMiao/zcf6.1천2026년 8월 31일 업데이트

UfoMiao의 스킬 모두 보기

이 스킬의 문제 신고