Effective Git
by @guguoyi
Intelligent Git workflow assistant following best practices. Use when user needs help with git commits, analyzing changes, writing commit messages, pushing c...
clawhub install effective-gitπ About This Skill
name: effective-git description: Intelligent Git workflow assistant following best practices. Use when user needs help with git commits, analyzing changes, writing commit messages, pushing code, rebasing, merging, or any git operations. Also triggers on quick command prefix 'gq' or 'gq:' for rapid operations like 'gq b:l' (list branches), 'gq b:n name' (create branch), 'gq:s' (status). Automatically analyzes changes, suggests appropriate commit strategies (amend vs new commit), follows project conventions, and ensures safe operations with confirmation for dangerous commands.
Effective Git
Smart Git workflow assistant that helps you commit, push, and manage code changes following best practices.
Getting Help
Quick help: When user asks "gq help", "gq:h", or "git help", run scripts/show_help.sh to display usage guide
Detailed help: When user asks about specific topics:
references/best-practices.mdreferences/conflict-resolution.mdreferences/quick-commands.mdUsage examples:
gq for quick operations (status, branch switching, etc.)Core Workflow
When helping with git operations, follow this sequence:
Quick Operations Mode
For simple, read-only operations or quick checks, use scripts/git_quick.sh:
When user asks for:
git_quick.sh b:lgit_quick.sh "b->" xxxgit_quick.sh b:n xxxgit_quick.sh sgit_quick.sh lgit_quick.sh "d"GIT_QUICK_DIFF_TERMINAL is set, opens in new terminal window
- Otherwise uses $PAGER (default: less)
- Staged changes: git_quick.sh "d:s"See references/quick-commands.md for full command list.
Full Workflow Mode
For commits, pushes, merges, and conflict resolution, follow the detailed workflow below:
1. Analyze Recent Changes
Run scripts/analyze_changes.sh to understand:
2. Determine Commit Strategy
Check if changes should amend the last commit or create a new one:
Use git commit --amend when:
Use git commit -m "message" when:
3. Check Project Conventions
Before writing commit message:
1. Review recent commit messages: git log --oneline -10
2. Look for patterns:
- Prefixes (feat:, fix:, chore:, etc.)
- Ticket references (#123, JIRA-456)
- Emoji usage (β¨, π, π)
- Capitalization style
3. If unclear, ask user about project conventions
4. Write Commit Message
Follow conventions from references/best-practices.md:
5. Safe Push Operations
Critical constraint: Only push to current branch.
Before pushing:
1. Confirm current branch: git branch --show-current
2. Show what will be pushed: git log origin/$(git branch --show-current)..HEAD --oneline
3. Ask user to confirm
4. Push: git push origin HEAD
Never use git push --force without explicit user confirmation.
Dangerous Operations
These require user confirmation before execution:
git push --force or git push -fgit reset --hardgit clean -fdgit rebase on shared/public branchesgit branch -D (force delete)Always explain the risk before asking for confirmation.
Conflict Resolution
Critical Principle: When resolving conflicts, the absolute priority is preserving all code. If unable to confidently resolve, you must summarize the issue and feedback to the user. DO NOT perform automatic merges.
Conflict Handling Workflow:
1. Pre-merge/Rebase Snapshot: Before attempting a merge or rebase, save a snapshot of the current state for documentation and safety.
scripts/save_diff.sh
# Also create backup branch
git branch -backup
This creates a git diff document before the merge.2. Detect and Analyze Conflicts: If conflicts arise during a merge or rebase:
scripts/analyze_conflicts.sh
This provides detailed three-way diff analysis for each conflicted file.3. Deep Conflict Analysis: For complex conflicts where both sides modified the same code: Analyze the intent: - What problem does each version solve? - What functionality does each add/remove/modify? - Is it a bug fix, feature, refactor, or optimization? Compare approaches: - Do they implement different algorithms? - Do they change APIs or interfaces differently? - What are the trade-offs (performance vs readability, simplicity vs robustness)? Determine resolution strategy: - Keep Both (Merge): Both changes are valuable and can be combined - Keep Ours: Our change is more complete/correct - Keep Theirs: Their change is more complete/correct - Rewrite: Neither is ideal, create better solution combining insights - Ask User: Cannot decide confidently, need user guidance
4. Present Analysis to User: When conflicts cannot be resolved automatically, create a structured summary:
- Show both versions of conflicting code
- Explain the intent and trade-offs of each
- Provide your recommendation with reasoning
- Ask for user's decision
- See references/conflict-resolution.md for detailed template
5. Post-Resolution Documentation: After conflicts are resolved:
# Generate diff of resolution
git diff --cached > .git/merge-diffs/resolution_$(date +%Y%m%d_%H%M%S).diff
# Show summary
git diff --cached --stat
6. Verify No Code Loss: After completing merge/rebase:
# Compare with backup branch
git diff -backup
# Review carefully for unexpected deletions
Special attention for edge cases:
references/conflict-resolution.md)references/conflict-resolution.md)Rebase & Merge
Interactive Rebase
# Clean up last N commits
git rebase -i HEAD~NRebase feature branch onto main
git checkout feature-branch
git fetch origin
git rebase origin/main
Merge Strategies
# Standard merge (preserves history)
git merge feature-branchSquash merge (single commit)
git merge --squash feature-branch
Common Tasks
Stash Changes
git stash # Stash current changes
git stash list # List stashes
git stash pop # Apply and remove last stash
git stash apply stash@{0} # Apply specific stash
Cherry-pick
git cherry-pick
Undo Changes
git restore # Discard working changes
git restore --staged # Unstage file
git reset HEAD~1 # Undo last commit (keep changes)
Resources
Quick Commands
For rapid git operations, use scripts/git_quick.sh with the gq prefix pattern:
Trigger pattern: When user message starts with gq: or uses git quick command syntax
Common commands:
gq b:l or gq:b:l - List branchesgq b-> - Switch to branchgq b:n - Create new branch from currentgq s - Quick statusgq l - Recent commitsgq d - Show diffUsage in conversation:
scripts/git_quick.sh b:lscripts/git_quick.sh "b->" featurescripts/git_quick.sh sβ οΈ Shell quoting rule: Always quote the command argument when calling git_quick.sh to prevent shell misinterpreting special characters. Use git_quick.sh "b->" , never git_quick.sh b-> (shell will treat > as redirection).
See references/quick-commands.md for full command list and usage patterns.
Important: Only trigger quick commands when user explicitly uses gq prefix or quick command syntax. Do not auto-trigger for general git questions.