| name | git:commit:push |
| description | Intelligent git commit and push with automatic conflict resolution, smart rebasing, and self-improving capabilities. This skill should be used when committing changes, pushing to remote, handling merge conflicts, or when the user invokes "/git-commit-push", "/git:commit:push", "commit and push", "sync with remote", or mentions git commit/push operations. Learns from each execution to become more efficient.
|
| user-invocable | true |
| disable-model-invocation | false |
Git Commit & Push (Self-Improving)
Commit staged/unstaged changes with intelligent message generation, handle upstream sync via rebase, resolve conflicts, and push to remote.
Accumulates learnings to improve future executions.
Execution Flow
┌─────────────────┐
│ 1. Gather State │ ← git status, branch, remotes, stash
├─────────────────┤
│ 2. Load Memory │ ← Read learnings.md for accumulated patterns
├─────────────────┤
│ 3. Stage Changes│ ← Selective or full staging
├─────────────────┤
│ 4. Sync Upstream│ ← Fetch + rebase (handle conflicts)
├─────────────────┤
│ 5. Smart Commit │ ← Analyze diff, generate message
├─────────────────┤
│ 6. Push │ ← Create remote branch if needed
├─────────────────┤
│ 7. Self-Improve │ ← Record learnings, update skill if needed
└─────────────────┘
Phase 1: Gather Repository State
Run all commands in parallel for efficiency:
git status --porcelain
git branch --show-current
git log -5 --oneline
git remote -v
git stash list
git rev-parse --abbrev-ref @{upstream} 2>/dev/null || echo "NO_UPSTREAM"
Decision Points:
- If no changes and no upstream diff → Exit early with "Nothing to commit"
- If untracked sensitive files (.env, credentials) → Warn and exclude
- If upstream exists → Plan for sync before push
Phase 2: Load Accumulated Learnings
Check for skill memory file:
cat .claude/skills/git-commit-push/references/learnings.md 2>/dev/null || echo "NO_LEARNINGS"
Apply any learned patterns:
- Commit message conventions for this repository
- Known conflict resolution patterns
- Branch naming conventions
- Files that should never be committed
Phase 3: Intelligent Staging
Pre-Staging Safety Check:
Check for and remove stale git lock files before staging:
if [ -f .git/index.lock ]; then
LOCK_AGE=$(( $(date +%s) - $(stat -f %m .git/index.lock 2>/dev/null || echo 0) ))
if [ "$LOCK_AGE" -gt 300 ]; then
echo "Removing stale lock file (${LOCK_AGE}s old)"
rm -f .git/index.lock
else
echo "WARNING: .git/index.lock exists (${LOCK_AGE}s old) - another git process may be running"
echo "Run 'ps aux | grep git' to check, or wait and retry"
fi
fi
Selective Staging Strategy:
- Exclude automatically:
.env*, *.local, credentials*, secrets*
- Files matching patterns in
.gitignore
- Large binary files (>10MB) without explicit approval
-
Stage by category:
git diff --name-only --diff-filter=M
git diff --name-only --diff-filter=A
git diff --name-only --diff-filter=D
git ls-files --others --exclude-standard
-
Stage all (default):
git add -A
Lock Contention Handling:
If lock errors persist (common with lazygit/git TUI tools):
- Check active git processes:
ps aux | grep git
- Wait for background operations:
sleep 2
- Retry with aggressive cleanup:
rm -f .git/index.lock && <git-command>
Phase 4: Upstream Synchronization
Rebase-First Strategy (cleaner history):
git fetch origin
UPSTREAM=$(git rev-parse --abbrev-ref @{upstream} 2>/dev/null)
if [ -n "$UPSTREAM" ]; then
BEHIND=$(git rev-list --count HEAD..@{upstream})
if [ "$BEHIND" -gt 0 ]; then
echo "Behind upstream by $BEHIND commits, rebasing..."
git stash push -m "auto-stash before rebase"
if ! git rebase origin/$(git branch --show-current); then
echo "Rebase failed - entering conflict resolution"
fi
fi
fi
Conflict Resolution Protocol:
When conflicts occur during rebase:
-
Identify conflict type:
git diff --name-only --diff-filter=U
-
For each conflicted file:
- Read the file to understand conflict markers
- Analyze
<<<<<<< HEAD (ours) vs >>>>>>> branch (theirs)
- Apply resolution strategy:
- Code files: Merge logically, preserve both changes if non-overlapping
- Config files: Prefer local unless upstream has critical fixes
- Lock files: Regenerate (
npm install, bundle install, etc.)
-
After resolution:
git add <resolved-file>
git rebase --continue
-
If rebase fails irrecoverably:
git rebase --abort
git stash pop
git merge origin/$(git branch --show-current)
Phase 5: Smart Commit Message Generation
Analysis Steps:
-
Gather change context:
git diff --cached --stat
git diff --cached --name-only
git diff --cached
-
Determine commit type from changes:
| Pattern | Type | Example |
|---|
New files in src/ | feat | New feature |
Modified *test* | test | Test changes |
Modified *.md, docs/ | docs | Documentation |
Modified pom.xml, package.json | chore | Dependencies |
| Deleted files only | refactor | Cleanup |
| Bug-related keywords in diff | fix | Bug fix |
| Formatting/style only | style | Code style |
- Generate message:
- Subject:
<type>: <imperative-verb> <concise-description> (≤50 chars)
- Body: Bullet points of significant changes (if >3 files)
- Footer:
Co-Authored-By: Claude <noreply@anthropic.com>
- Commit with HEREDOC for proper formatting:
git commit -m "$(cat <<'EOF'
:
Co-Authored-By: Claude noreply@anthropic.com
EOF
)"
## Phase 6: Push to Remote
```bash
BRANCH=$(git branch --show-current)
# Check if remote branch exists
if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
git push origin "$BRANCH"
else
echo "Creating new remote branch: $BRANCH"
git push -u origin "$BRANCH"
fi
Push Failure Handling:
- If rejected due to non-fast-forward → Re-run Phase 4 (sync)
- If authentication fails → Inform user to check credentials
- If hooks fail → Show hook output, ask user how to proceed
Phase 7: Self-Improvement Protocol
After each execution, evaluate and record learnings.
Efficiency Metrics to Track
| Metric | Trigger for Learning |
|---|
| Conflict frequency | Same file conflicts >2x → Add to learnings |
| Commit type accuracy | User amends message → Learn correction |
| Rebase failures | >1 failure → Consider merge strategy for repo |
| Push rejections | Pattern of rejections → Adjust sync frequency |
Recording Learnings
Append to references/learnings.md:
## Learning: [DATE]
**Trigger:** <what happened>
**Pattern:** <what was learned>
**Action:** <how to apply in future>
Self-Modification Protocol
When a pattern is encountered 3+ times, update the SKILL.md itself:
-
Read current skill:
cat .claude/skills/git-commit-push/SKILL.md
-
Identify improvement location:
- New conflict resolution pattern → Add to Phase 4
- New commit type pattern → Add to Phase 5 table
- New exclusion pattern → Add to Phase 3
-
Apply targeted edit using the Edit tool
-
Log the self-modification:
## Self-Modification: [DATE]
**Reason:** <why modification was needed>
**Change:** <what was modified>
**Location:** <which phase/section>
Safety Rules
NEVER:
git push --force (unless explicitly requested)
- Commit files matching:
.env*, *credential*, *secret*, *.pem, *.key
- Skip pre-commit hooks without explicit approval
- Amend commits already pushed to shared branches
ALWAYS:
- Verify working tree is clean after operations
- Preserve user's stashed changes
- Show summary of what was committed and pushed
Output Format
After successful execution, display:
✓ Committed: <commit-hash> <commit-message-subject>
✓ Pushed to: origin/<branch>
Files: <count> changed (+<additions> -<deletions>)
[Learnings recorded: <count> new patterns]
References
- See
references/learnings.md for accumulated patterns and learnings
- See
references/conflict-patterns.md for known conflict resolution strategies