Safe git operations including commits, branches, merges, worktrees, and conflict resolution. Use when user wants to commit and push changes, manage branches, resolve conflicts, or create isolated workspaces. Activates when user says "commit", "push", "merge", "branch", "pull", "rebase", "worktree", "conflict", or similar git workflow requests.
Comprehensive git operations toolkit with safety-first approach, including isolated worktrees and branch finishing workflows.
Keywords: git, commit, merge, rebase, push, pull, branch, checkout, stash, conflict, github, pull request, PR, worktree, isolated workspace
Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching contexts.
Core Principle: Systematic directory selection + safety verification = reliable isolation
Follow this priority order:
Check Existing Directories
ls -d .worktrees 2>/dev/null # Preferred (hidden)
ls -d worktrees 2>/dev/null # Alternative
If found, use that directory. If both exist, .worktrees wins.
Check Project Documentation
Look for preferences in CLAUDE.md, .github/copilot-instructions.md, or README
Ask User If no directory exists and no preference specified:
.worktrees/ (project-local, hidden)worktrees/ (project-local, visible)~/.config/copilot-skills/worktrees/<project-name>/ (global location)For Project-Local Directories (.worktrees or worktrees):
MUST verify .gitignore before creating worktree:
# Check if directory pattern in .gitignore
grep -q "^\.worktrees/$" .gitignore || grep -q "^worktrees/$" .gitignore
If NOT in .gitignore:
Why Critical: Prevents accidentally committing worktree contents to repository.
For Global Directory (~/.config/copilot-skills/worktrees):
project=$(basename "$(git rev-parse --show-toplevel)")
# Determine full path based on location choice
case $LOCATION in
.worktrees|worktrees)
path="$LOCATION/$BRANCH_NAME"
;;
~/.config/copilot-skills/worktrees/*)
path="~/.config/copilot-skills/worktrees/$project/$BRANCH_NAME"
;;
esac
# Create worktree with new branch
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"
Auto-detect and run appropriate setup:
# Node.js
if [ -f package.json ]; then npm install; fi
# Rust
if [ -f Cargo.toml ]; then cargo build; fi
# Python
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi
# Go
if [ -f go.mod ]; then go mod download; fi
# Ruby
if [ -f Gemfile ]; then bundle install; fi
Run tests to ensure worktree starts clean:
# Examples - use project-appropriate command
npm test
cargo test
pytest
go test ./...
bundle exec rspec
If tests fail: Report failures, ask whether to proceed or investigate. If tests pass: Report ready.
Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>
# List all worktrees
git worktree list
# Remove worktree
git worktree remove <path>
# Prune stale worktree administrative data
git worktree prune
# Move worktree to new location
git worktree move <source> <destination>
# Lock worktree (prevent removal)
git worktree lock <path>
# Unlock worktree
git worktree unlock <path>
Guide completion of development work by presenting clear options and handling chosen workflow.
Core Principle: Verify tests → Present options → Execute choice → Clean up
Before presenting options, verify tests pass:
# Run project's test suite
npm test # Node.js
cargo test # Rust
pytest # Python
go test ./... # Go
bundle exec rspec # Ruby
If tests fail:
Tests failing (<N> failures). Must fix before completing:
[Show failures]
Cannot proceed with merge/PR until tests pass.
Stop. Don't proceed to Step 2.
If tests pass: Continue to Step 2.
# Try common base branches
git merge-base HEAD main 2>/dev/null || \
git merge-base HEAD master 2>/dev/null || \
git merge-base HEAD develop 2>/dev/null
Or ask: "This branch split from main - is that correct?"
Present exactly these 4 options:
Implementation complete. What would you like to do?
1. Merge back to <base-branch> locally
2. Push and create a Pull Request
3. Keep the branch as-is (I'll handle it later)
4. Discard this work
Which option?
Don't add explanation - keep options concise.
Option 1: Merge Locally
# Switch to base branch
git checkout <base-branch>
# Pull latest
git pull
# Merge feature branch
git merge <feature-branch>
# Verify tests on merged result
<test command>
# If tests pass
git branch -d <feature-branch>
Then: Cleanup worktree (Step 5)
Option 2: Push and Create PR
# Push branch
git push -u origin <feature-branch>
# Create PR
gh pr create --title "<title>" --body "$(cat <<'EOF'
## Summary
<2-3 bullets of what changed>
## Test Plan
- [ ] <verification steps>
## Related Issues
Closes #<issue-number>
EOF
)"
Then: Cleanup worktree (Step 5)
Option 3: Keep As-Is
Report: "Keeping branch <name>. Worktree preserved at <path>."
Don't cleanup worktree.
Option 4: Discard
Confirm first:
This will permanently delete:
- Branch <name>
- All commits: <commit-list>
- Worktree at <path>
Type 'discard' to confirm.
Wait for exact confirmation.
If confirmed:
git checkout <base-branch>
git branch -D <feature-branch>
Then: Cleanup worktree (Step 5)
For Options 1, 2, 4:
Check if in worktree:
git worktree list | grep $(git branch --show-current)
If yes:
# Exit worktree first
cd $(git rev-parse --show-toplevel)
# Remove worktree
git worktree remove <worktree-path>
For Option 3: Keep worktree.
| Option | Merge | Push | Keep Worktree | Cleanup Branch | |--------|-------|------|---------------|----------------| | 1. Merge locally | ✓ | - | - | ✓ | | 2. Create PR | - | ✓ | ✓ | - | | 3. Keep as-is | - | - | ✓ | - | | 4. Discard | - | - | - | ✓ (force) |
<type>(<scope>): <subject>
<body>
<footer>
feat: - New featurefix: - Bug fixdocs: - Documentation changesstyle: - Code style changes (formatting, no logic change)refactor: - Code refactoringtest: - Adding or updating testschore: - Maintenance tasksperf: - Performance improvementsci: - CI/CD changesfeat(worktrees): add isolated workspace creation
fix(git-ops): resolve merge conflict detection bug
docs(readme): update worktree usage instructions
refactor(skills): reorganize git operations structure
chore(deps): update git version requirement
Located in .github/copilot-skills/git-ops/scripts/:
# Safe git execution with validation
./git_safe_exec.sh [--dry-run] [--backup] <command>
# Interactive commit helper
./commit_helper.sh [--type <type>] [--scope <scope>]
# Conflict resolution assistant
./conflict_resolver.sh [--summary] [--interactive]
All scripts output to terminal (no file generation) for AI parsing.
.worktrees/ for project-local (hidden from file browsers)git status before any operationgit diff --staged to review before commit--force-with-lease instead of --forceFor additional details:
下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer