Git workflow, code quality, context management and testing commands: - commit, push, pr, issue - git operations - simplify, refactor, verify, check - code quality - catchup, onboard, save, cleanup - context management - test, format, sync - development utilities Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2.1 KiB
Safe Push
Pre-computed Context
Current Branch:
!git branch --show-current
Upstream Branch:
!git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || echo "No upstream configured"
Commits to Push:
!git log --oneline @{u}..HEAD 2>/dev/null || echo "No upstream or no commits to push"
Local vs Remote:
!git status -sb | head -1
Uncommitted Changes:
!git status --porcelain | wc -l | xargs -I{} sh -c 'if [ {} -eq 0 ]; then echo "Working tree clean"; else echo "{} uncommitted changes"; fi'
Instructions
You are pushing commits to the remote repository with safety checks.
1. Pre-flight Checks
Before pushing, verify:
- No uncommitted changes: Ensure everything is committed
- Not pushing to protected branch: Warn if pushing directly to main/master
- Upstream configured: Set upstream if needed
2. Protected Branch Warning
If current branch is main or master:
WARNING: You are pushing directly to the main branch.
Consider creating a feature branch and PR instead.
Continue? [y/N]
3. Set Upstream (if needed)
If no upstream is configured:
git push -u origin $(git branch --show-current)
4. Execute Push
Standard push:
git push
With explicit remote/branch:
git push origin <branch>
5. Verify
After push, show status:
git status -sb
Safety Rules
NEVER run these without explicit user request:
git push --forcegit push --force-with-leasegit push -f
If push is rejected:
- Run
git fetchto see remote state - Explain the divergence
- Suggest:
git pull --rebasethen push again - Only suggest force push if user explicitly asks
Common Scenarios
First push of new branch:
git push -u origin feature/my-branch
Push after rebase (requires user confirmation):
# Only with explicit user approval:
git push --force-with-lease
Push to different remote:
git push upstream main