worktree-setup-hook
Post-checkout git hook for automatic worktree setup. Use when: (1) Setting up automatic configuration for new git worktrees, (2) Creating post-checkout hooks that detect new worktrees and run setup tasks, (3) Configuring worktrees to automatically copy env files and install dependencies
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Worktree Setup Hook
Provides a post-checkout git hook template that automatically configures new git worktrees by detecting new worktree creation and running setup tasks.
Overview
The hook detects when a new worktree is created (not a regular checkout) and automatically:
- Copies environment files (.env, .env.local, etc.)
- Detects the project's package manager and installs dependencies
- Runs setup scripts if available
Quick Start
Install the hook template:
cp .cursor/skills/worktree-setup-hook/assets/hook-templates/post-checkout .git/hooks/post-checkout
chmod +x .git/hooks/post-checkout
The hook will automatically run after git worktree add completes.
How It Works
Worktree Detection
The hook detects new worktrees by checking if the previous HEAD is the null-ref (0000000000000000000000000000000000000000). This is how git indicates a new worktree creation.
Setup Tasks
-
Environment Files: Copies
.env.exampleto.env,.env.local.exampleto.env.local, or copies env files from the main worktree -
Package Manager Detection: Automatically detects and installs dependencies:
-
package.json→ npm or yarn -
requirements.txt→ pip -
Cargo.toml→ cargo -
go.mod→ go -
Gemfile→ bundle
-
-
Setup Scripts: Runs
setup.shorscripts/setup.shif present and executable
Installation
See setup-guide.md for detailed installation instructions, including:
- Step-by-step installation
- Handling existing hooks
- Backup procedures
- Troubleshooting
Customization
The hook is a standard POSIX shell script. Edit .git/hooks/post-checkout to add custom setup steps or modify behavior.
Resources
-
Hook Template:
assets/hook-templates/post-checkout- The main hook script -
Setup Guide:
references/setup-guide.md- Detailed installation and configuration instructions
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!