# Git

> Git operations for commit, push, PR, and ship workflows with safety rules. Use for any version control task.

- Skill: `shir-bruchim/git` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add shir-bruchim/git`
- Raw SKILL.md: https://api.skillmd.com/api/skills/shir-bruchim/git/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Productivity
- Author: shir-bruchim (https://skillmd.com/u/shir-bruchim)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/shir-bruchim/git

---


<essential_principles>

<git_safety>
**Never run without explicit user request:**
- `git push --force` to main/master
- `git reset --hard`
- `--no-verify` flag (skip hooks)
- `git commit --amend` on pushed commits
- Direct push to main/master (create feature branch first)

**Always verify before acting:**
- `git status` before staging
- `git log --oneline -5` for commit style
- Check remote tracking before push
- **Re-check `git log`/`git status` before assuming your session's work is still uncommitted.** An external tool (IDE Git panel, a teammate, a pre-commit flow) may have committed "held" changes mid-session. Acting on the stale "it's uncommitted" assumption risks a duplicate commit or clobbering what already landed — confirm what's actually staged/committed first.
- **PR merge-state before pushing to an existing PR branch** — if the PR already merged, the push orphans the commits (nobody re-reviews/re-merges them; the change silently never ships). Check `gh pr view <branch> --json state,mergedAt` and stop if merged — branch off the default branch for the follow-up instead.

**`git worktree remove` is destructive — sweep first.** Before removing ANY worktree, in EACH worktree run:
- `git status --short` — surface uncommitted edits (modified, untracked, staged)
- `git log --oneline <upstream>..HEAD` — surface unpushed commits
- If either is non-empty, STOP. Ask the user explicitly: (a) commit + push it now, (b) save as a patch (`git diff > /tmp/<name>.patch`) for later, or (c) discard. Don't assume "the work is mirrored elsewhere" — the whole reason worktrees exist is to hold work that isn't yet on the canonical branch. Surfacing the diff one-line-per-file BEFORE the user makes the call is the right move; running `git worktree remove --force` to bypass a "worktree contains modified files" warning is the wrong one. Also delete stale local branch labels (`git branch -D <name>`) AFTER worktree removal if the label points at a commit the user has confirmed they're done with.

**Branch naming:** See `~/.claude/rules/git-workflow/RULE.md` §"Branch Strategy".
</git_safety>

<commit_format>
Commit message structure:
```
type(scope): short description

- What changed (if not obvious from description)
- Why it changed (motivation)

Co-Authored-By: Claude <noreply@anthropic.com>
```

Types: see `~/.claude/rules/git-workflow/RULE.md` §"Commit Messages (Conventional Commits)" for the canonical type list.

Use HEREDOC for multi-line messages:
```bash
git commit -m "$(cat <<'EOF'
feat(auth): add JWT refresh token rotation

- Rotates refresh tokens on every use
- Prevents replay attacks on stolen tokens

Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
```
</commit_format>

<pr_format>
PR body:
```markdown
## Summary
- [What this PR does in 1-3 bullets]

## Test plan
- [ ] [Test 1]
- [ ] [Test 2]

## Changes
- [File 1]: [What changed]
- [File 2]: [What changed]
```
</pr_format>

</essential_principles>

<intake>
What would you like to do?

1. **Commit** — Stage and commit changes
2. **Push** — Push commits to remote
3. **PR** — Open a pull request
4. **Ship** — Full workflow: commit + push + PR

**Wait for response.**
</intake>

<routing>
| Response | Workflow |
|----------|----------|
| 1, "commit" | `workflows/commit.md` |
| 2, "push" | `workflows/push.md` |
| 3, "pr", "pull request" | `workflows/pr.md` |
| 4, "ship", "all" | commit → push → pr (sequential) |
</routing>

<workflows_index>
| Workflow | Purpose |
|----------|---------|
| commit.md | Stage changes and create commit |
| push.md | Push to remote, create branch if needed |
| pr.md | Create pull request with gh CLI |
</workflows_index>

