본문으로 건너뛰기
Skillpedia
배포 및 클라우드 (DevOps)29k · #9588

git-worktree-manager

하는 일

이 스킬은 git 프로젝트의 추가 작업 복사본을 만들어 여러 브랜치를 동시에 열 수 있게 합니다. 더 이상 필요 없는 복사본도 제거합니다. 한 번에 여러 기능을 작업하는 개발자에게 맞습니다.

사용하는 경우

  • ✓같은 프로젝트의 브랜치 두 개 이상을 동시에 작업해야 할 때.
  • ✓여러 AI 에이전트가 서로 충돌하지 않도록 각자 브랜치에서 작업해야 할 때.
  • ✓오래된 작업 복사본이 쌓여서 안전하게 지우고 싶을 때.

스킬 링크

https://github.com/alirezarezvani/claude-skills/blob/main/engineering/skills/git-worktree-manager/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/alirezarezvani/claude-skills/blob/main/engineering/skills/git-worktree-manager/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“새 로그인 기능을 위해 이 프로젝트의 별도 작업 복사본을 만들어서, 현재 브랜치는 열어 둘 수 있게 해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

스크립트를 써서 각 복사본을 별도 폴더에 만들고, 여유 있는 포트를 할당하며 환경 파일을 복사합니다. 정리하기 전에 저장되지 않은 변경이 있는지 먼저 확인합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Git Worktree Manager

Tier: POWERFUL
Category: Engineering
Domain: Parallel Development & Branch Isolation

Overview

Use this skill to run parallel feature work safely with Git worktrees. It standardizes branch isolation, port allocation, environment sync, and cleanup so each worktree behaves like an independent local app without stepping on another branch.

This skill is optimized for multi-agent workflows where each agent or terminal session owns one worktree.

Core Capabilities

  • Create worktrees from new or existing branches with deterministic naming
  • Auto-allocate non-conflicting ports per worktree and persist assignments
  • Copy local environment files (.env*) from main repo to new worktree
  • Optionally install dependencies based on lockfile detection
  • Detect stale worktrees and uncommitted changes before cleanup
  • Identify merged branches and safely remove outdated worktrees

When to Use

  • You need 2+ concurrent branches open locally
  • You want isolated dev servers for feature, hotfix, and PR validation
  • You are working with multiple agents that must not share a branch
  • Your current branch is blocked but you need to ship a quick fix now
  • You want repeatable cleanup instead of ad-hoc rm -rf operations

Key Workflows

1. Create a Fully-Prepared Worktree

  1. Pick a branch name and worktree name.
  2. Run the manager script (creates branch if missing).
  3. Review generated port map.
  4. Start app using allocated ports.
python scripts/worktree_manager.py \
  --repo . \
  --branch feature/new-auth \
  --name wt-auth \
  --base-branch main \
  --install-deps \
  --format text

If you use JSON automation input:

cat config.json | python scripts/worktree_manager.py --format json
# or
python scripts/worktree_manager.py --input config.json --format json

2. Run Parallel Sessions

Recommended convention:

  • Main repo: integration branch (main/develop) on default port
  • Worktree A: feature branch + offset ports
  • Worktree B: hotfix branch + next offset

Each worktree contains .worktree-ports.json with assigned ports.

3. Cleanup with Safety Checks

  1. Scan all worktrees and stale age.
  2. Inspect dirty trees and branch merge status.
  3. Remove only merged + clean worktrees, or force explicitly.
python scripts/worktree_cleanup.py --repo . --stale-days 14 --format text
python scripts/worktree_cleanup.py --repo . --remove-merged --format text

4. Docker Compose Pattern

Use per-worktree override files mapped from allocated ports. The script outputs a deterministic port map; apply it to docker-compose.worktree.yml.

See docker-compose-patterns.md for concrete templates.

5. Port Allocation Strategy

Default strategy is base + (index * stride) with collision checks:

  • App: 3000
  • Postgres: 5432
  • Redis: 6379
  • Stride: 10

See port-allocation-strategy.md for the full strategy and edge cases.

Script Interfaces

  • python scripts/worktree_manager.py --help
    • Create/list worktrees
    • Allocate/persist ports
    • Copy .env* files
    • Optional dependency installation
  • python scripts/worktree_cleanup.py --help
    • Stale detection by age
    • Dirty-state detection
    • Merged-branch detection
    • Optional safe removal

Both tools support stdin JSON and --input file mode for automation pipelines.

Common Pitfalls

  1. Creating worktrees inside the main repo directory
  2. Reusing localhost:3000 across all branches
  3. Sharing one database URL across isolated feature branches
  4. Removing a worktree with uncommitted changes
  5. Forgetting to prune old metadata after branch deletion
  6. Assuming merged status without checking against the target branch

Best Practices

  1. One branch per worktree, one agent per worktree.
  2. Keep worktrees short-lived; remove after merge.
  3. Use a deterministic naming pattern (wt-<topic>).
  4. Persist port mappings in file, not memory or terminal notes.
  5. Run cleanup scan weekly in active repos.
  6. Use --format json for machine flows and --format text for human review.
  7. Never force-remove dirty worktrees unless changes are intentionally discarded.

Validation Checklist

Before claiming setup complete:

  1. git worktree list shows expected path + branch.
  2. .worktree-ports.json exists and contains unique ports.
  3. .env files copied successfully (if present in source repo).
  4. Dependency ins
자주 묻는 질문

저장하지 않은 작업을 지우나요?

정리 단계에서 커밋되지 않은 변경을 먼저 확인하므로, 작업을 잃지 않도록 설계되어 있습니다.

각 복사본이 별도 포트에서 실행되나요?

네. 두 개의 개발 서버가 충돌하지 않도록 각 작업 복사본에 포트를 할당합니다.

내 로컬 설정 파일도 복사하나요?

네. 메인 프로젝트의 로컬 환경 파일을 새 작업 복사본에 복사합니다.

상세 정보

작성자의 원본 설명

Use when running several branches or agents in parallel on one repo. Creates worktrees with isolated ports and env via worktree_manager.py and removes stale ones with worktree_cleanup.py.

repo: alirezarezvani/claude-skills

인기도

GitHub 스타
29k
순위
#9588
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬