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>
108 lines
2.1 KiB
Markdown
108 lines
2.1 KiB
Markdown
---
|
|
description: Push to remote with safety checks
|
|
argument-hint: [remote] [branch] - Optional remote and branch (defaults to origin and current branch)
|
|
---
|
|
|
|
# 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:
|
|
```bash
|
|
git push -u origin $(git branch --show-current)
|
|
```
|
|
|
|
### 4. Execute Push
|
|
|
|
Standard push:
|
|
```bash
|
|
git push
|
|
```
|
|
|
|
With explicit remote/branch:
|
|
```bash
|
|
git push origin <branch>
|
|
```
|
|
|
|
### 5. Verify
|
|
|
|
After push, show status:
|
|
```bash
|
|
git status -sb
|
|
```
|
|
|
|
---
|
|
|
|
## Safety Rules
|
|
|
|
**NEVER run these without explicit user request:**
|
|
- `git push --force`
|
|
- `git push --force-with-lease`
|
|
- `git push -f`
|
|
|
|
**If push is rejected:**
|
|
1. Run `git fetch` to see remote state
|
|
2. Explain the divergence
|
|
3. Suggest: `git pull --rebase` then push again
|
|
4. Only suggest force push if user explicitly asks
|
|
|
|
---
|
|
|
|
## Common Scenarios
|
|
|
|
**First push of new branch:**
|
|
```bash
|
|
git push -u origin feature/my-branch
|
|
```
|
|
|
|
**Push after rebase (requires user confirmation):**
|
|
```bash
|
|
# Only with explicit user approval:
|
|
git push --force-with-lease
|
|
```
|
|
|
|
**Push to different remote:**
|
|
```bash
|
|
git push upstream main
|
|
```
|