Claude-skill-registry git-operations
Git command procedures for branch management, commits, and worktrees.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/git-operations-benjaminrose805-react-basecamp" ~/.claude/skills/majiayu000-claude-skill-registry-git-operations && rm -rf "$T"
skills/data/git-operations-benjaminrose805-react-basecamp/SKILL.mdGit Operations Skill
Git command procedures for branch management, commits, and worktrees.
When Used
| Agent | Phase |
|---|---|
| git-agent | All actions |
CLI Tools
All operations use native git and GitHub CLI (
gh):
# Verify gh CLI is authenticated gh auth status # If not authenticated, run: gh auth login
Note: The github MCP server has been replaced with
gh CLI commands. See pr-operations skill for PR-related commands.
Procedures
1. Status
Show current git state:
git status git log --oneline -5 git branch -vv
Output: Current branch, uncommitted changes, recent commits.
2. Branch Create
Create and switch to a new branch:
git checkout -b <type>/<name>
Branch Types:
| Prefix | Use For | Example |
|---|---|---|
| New features | |
| Bug fixes | |
| Code improvements | |
| Documentation | |
Validation:
- Never create branch from dirty working directory
- Always branch from up-to-date main
git fetch origin git checkout main git pull origin main git checkout -b <type>/<name>
3. Branch Switch
Switch to an existing branch:
git checkout <branch>
With uncommitted changes:
# Option 1: Stash changes git stash git checkout <branch> # Option 2: Commit first git add <files> git commit -m "wip: save progress" git checkout <branch>
4. Sync with Main
Update current branch with latest main:
git fetch origin git rebase origin/main
On conflict:
# Fix conflicts in files git add <resolved-files> git rebase --continue
If rebase is problematic:
git rebase --abort git merge origin/main
5. Commit
Create a conventional commit:
# Stage specific files (never use -A or .) git add <file1> <file2> # Commit with message git commit -m "<type>: <description> <optional body> Co-Authored-By: Claude <noreply@anthropic.com>"
Commit Types:
| Type | Use For |
|---|---|
| New feature |
| Bug fix |
| Code change that neither fixes nor adds |
| Documentation only |
| Adding or updating tests |
| Maintenance, dependencies |
Pre-commit checks:
pnpm lint && pnpm typecheck
6. Worktree Add
Create a new worktree for parallel development:
# Create worktree with new branch git worktree add ../<repo>--<feature> -b feature/<feature> # Create worktree from existing branch git worktree add ../<repo>--<feature> feature/<feature>
Example:
git worktree add ../react-basecamp--prompt-manager -b feature/prompt-manager
Directory structure:
~/basecamp/ ├── react-basecamp/ # Main worktree (main branch) ├── react-basecamp--prompt-manager/ # Worktree for feature └── react-basecamp--other-feature/ # Another worktree
7. Worktree Remove
Remove a worktree when done:
git worktree remove ../<repo>--<feature>
If worktree has uncommitted changes:
# Force remove (discards changes) git worktree remove --force ../<repo>--<feature> # Or commit/stash changes first cd ../<repo>--<feature> git stash cd ../<repo> git worktree remove ../<repo>--<feature>
8. Worktree List
Show all worktrees:
git worktree list
9. Cleanup
Delete merged branches:
# Delete local merged branches git branch --merged main | grep -v "main" | xargs -r git branch -d # Prune remote-tracking branches git fetch --prune
Error Handling
| Error | How to Handle |
|---|---|
| Merge conflict | Resolve manually, then continue |
| Dirty working dir | Stash or commit before switching |
| Branch exists | Check if intentional, use different name |
| Worktree locked | Remove lock file or use --force |
Output
Return operation result:
## Git Operation: <action> **Status:** SUCCESS / FAILED **Details:** - <operation-specific details> **Current State:** - Branch: `feature/prompt-manager` - Uncommitted: 0 files