Skip to main content

Git Rules

Never commit to main or master. If on one, branch off immediately.
Clean commits, PRs, and issues for a React Native / Expo codebase.

Recon (Always Run First)

Before planning anything, gather full context:
git status
git diff --stat
git diff
git diff --staged
git log --oneline --decorate -n 20
git branch --show-current
Then write a 3–7 bullet summary of what changed:
  • 2–4 user-facing bullets (what the user would notice)
  • 1–3 technical bullets (architecture, perf, cleanup)
This summary drives commit messages, PR body, and issue descriptions.

Branch Naming

Format

type/scope-description

Examples

git checkout -b feat/nfc-payment-flow

Rename Branch If Scope Changes

git branch -m type/new-scope-description

Commit Conventions

Format

type(scope): imperative subject (≤72 chars)

Optional body — why, tradeoffs, edge cases.
Keep it short. Use when subject alone isn't enough.

Types

TypeUse For
featNew feature
fixBug fix
refactorCode restructuring (no behavior change)
perfPerformance improvement
testAdding or updating tests
docsDocumentation changes
styleCode formatting, missing semicolons, etc.
buildBuild system or external dependencies
ciCI configuration and scripts
choreMaintenance tasks

Scope

Derive from diff paths first, then feature intent. Pick one primary scope per commit.
ScopeCovers
uicomponents/ui/*, general visual/layout
appapp/* top-level, offline shell, launch
cameraQR scanning, camera permissions
nfcNFC payment flow, NFC rollback
mintMint info, trust sheets, mint selection
npcNPC plugin, NPC mint store
walletWallet operations, transaction history
receiveReceive flow, token redeem
rebalanceRebalance operations
transactionsTransaction screens, details
keyringP2PK key management
keysKey derivation, NIP-06, NUT-13
profileMulti-profile, profile switch
settingsSettings pages, preferences
homeDashboard widgets
exploreExplore tab, wallet health
mapMap flow, BTC Map
listsVirtualized feeds
popupToast/sheet system
themeTheme engine
providersproviders/*, NDK, ThemeProvider
storestores/*, Zustand stores
hookshooks/*
blockscomponents/blocks/*
txTransaction timeline
widgetiOS/Android widget
repoRepo-level docs
toolingLint, knip, prettier, quality gate
ciGitHub Actions, CI
patchespatches/*
metrometro.config.*
rules.cursor/rules/* docs
readmeREADME changes
Create new scopes freely when the change doesn’t fit an existing one.Derive from the most specific directory or feature name — don’t force-fit into the table above.New scopes are cheap; vague scopes are expensive.

Commit Message Examples

feat(nfc): add NFC tap payment support

Implements NDEF Type 4 Tag protocol for contactless payments.
Includes rollback handling and POS payment recovery.

When to Commit

Commit if any are true:
  • ✅ UI or user behavior changed
  • ✅ Non-trivial fix, perf improvement, or refactor
  • ✅ New files added or risky logic touched (payments, keys, storage, networking)
  • ✅ Config, tooling, patches, or lockfile changed
Skip only if truly trivial or user explicitly says no.

Staging

Stage precisely — use git add -p for mixed files. Plan 2–6 commits for non-trivial work.
# Stage specific files
git add path/to/file.ts

# Interactive staging for partial changes
git add -p path/to/file.ts

# Stage all changes (use sparingly)
git add .
Never commit a broken state (partial syntax, missing imports).
Keep deps/lockfiles/patches in separate commits:
# Separate commit for dependencies
git add package.json yarn.lock
git commit -m "build(deps): add expo-nfc-manager"

# Then commit the feature
git add app/nfc/
git commit -m "feat(nfc): add NFC payment flow"

Validation Gate

Run all five before every commit.
npm run lint
npm run type-check
npm run pretty:check
npm run knip
npm test
If formatting fails, fix with npm run pretty then re-check. If any other check fails, fix and git commit --amend.
Only claim what you actually ran. Don’t skip checks.

Secret Scanning (Non-Negotiable)

Before staging ANY file, scan diffs for secrets. Refuse to commit if found:
Never commit these:
  • Passwords, API keys, tokens, session cookies
  • Mnemonics (12–24 words), xprv, WIF, raw private keys
  • Nostr secrets (nsec1...), hex private keys
  • .env contents, credential files

If Found

1

Remove from diff

Unstage the file and remove the secret.
2

Confirm .gitignore coverage

Add the file pattern to .gitignore if not already covered.
3

Advise secret rotation

If the secret was already committed, rotate it immediately.

Pull Requests

Push and open PR when work is ready for review:
git push -u origin $(git branch --show-current)
gh pr create --title "feat(nfc): add NFC payment support" --body "$(cat <<'EOF'
## What / Why
- Adds NFC tap payments for Lightning invoices and ecash
- Users can now pay by tapping NFC-enabled POS devices

## What changed
- New `helper/nfc.ts` with NDEF Type 4 Tag protocol
- NFC handler in wallet tab layout with mint selection
- Rollback handling for failed NFC payments
- POS payment recovery flow

## Test plan
1. Enable NFC on device
2. Tap NFC-enabled POS terminal
3. Verify payment flow completes
4. Test rollback on payment failure

## Notes / Risks
- Requires Android 4.4+ or iOS 13+
- NFC must be enabled in device settings
EOF
)"

PR Rules

  • Title = final conventional commit subject (this becomes the squash-merge message)
  • Body is the commit message body — concise, scannable, no filler
  • Use gh pr edit to update if scope changes after opening
  • Link related issues: Closes #N or Related: #N

PR Template

## What / Why
- <2-3 bullets: problem solved or feature added>

## What changed
- <3-5 bullets: key code changes>

## Test plan
1. <concrete verification steps>

## Notes / Risks
- <anything reviewers should watch for, or "None">

GitHub Issues (Rare — Unresolved Bugs Only)

File an issue only when:
  • A bug was investigated but couldn’t be fixed in the current session
  • The root cause is identified but the fix is out of scope or risky
  • A flaky behavior needs tracking for future debugging
gh issue create --title "fix(mint): connection timeout after network error" --body "$(cat <<'EOF'
## Problem
Mint connections timeout after a network error without retrying,
leaving the wallet in a disconnected state.

## Reproduction
1. Connect to mint
2. Toggle airplane mode on/off
3. Observe connection timeout error
4. Mint remains disconnected

## Investigation so far
- Ruled out: WebSocket library bug
- Likely cause: Missing reconnect handler in `MintClient.ts:123`
- Timeout occurs at 30s, no retry attempted

## Relevant code
- `helper/coco/MintClient.ts` — WebSocket connection management
- `stores/mintStore.ts` — Mint connection state

## Suggested fix
- Add exponential backoff retry logic
- Max 3 retries before showing error to user
EOF
)"

Issue Rules

  • Title is a conventional commit subject (so it reads well in lists)
  • Body captures agent context — the investigation is the value
  • Label if gh labels are available: bug, investigation, help-wanted
  • Never file issues for feature requests or tasks — only unresolved bugs from the current session

Issue Template

## Problem
<1-2 sentences: what's broken and when it happens>

## Reproduction
1. <minimal steps>

## Investigation so far
- <what was tried, what was ruled out>
- <root cause hypothesis if any>

## Relevant code
- `path/to/file.ts`<what's relevant there>

## Suggested fix
- <approach if known, or "Needs further investigation">

Quick Reference

ActionCommand
New branchgit checkout -b type/scope-desc
Stage hunksgit add -p
Commitgit commit -m "type(scope): subject"
Amendgit commit --amend
Pushgit push -u origin $(git branch --show-current)
Force push (rewrite)git push --force-with-lease
Open PRgh pr create --title "..." --body "..."
Update PRgh pr edit --title "..." --body "..."
File issuegh issue create --title "..." --body "..."
View PR statusgh pr status

Complete Workflow Example

1

Create branch

git checkout -b feat/nfc-payment
2

Make changes

Write code following contributing guidelines.
3

Run quality checks

npm run lint
npm run type-check
npm run pretty:check
npm run knip
npm test
4

Stage changes

git add app/nfc/
5

Commit

git commit -m "feat(nfc): add NFC tap payment support

Implements NDEF Type 4 Tag protocol for contactless payments.
Includes rollback handling and POS payment recovery."
6

Push and create PR

git push -u origin feat/nfc-payment
gh pr create --title "feat(nfc): add NFC tap payment support" --body "..."

Build docs developers (and LLMs) love