Principles for humans and AI agents to work effectively with Git and GitHub.
AI agents that don't understand repository state cause downstream problems:
- Working on stale branches causes merge conflicts
- Not checking remote changes leads to lost work
- Pushing without resolving conflicts pollutes history
These problems compound when multiple agents or humans work together.
Before making any changes:
- Fetch the latest from remote to see what changed
- Check your current branch against the remote
- Understand if new commits exist that may affect your work
For AI agents: confirm the repo state is current before editing.
[AI agents should fetch before editing: enable/disable]
Before committing:
- Check
git statusto see current state - Review
git logor diff to understand recent changes - Identify if rebasing or merging is needed
[Require pre-commit remote check: yes/no]
Never push with unresolved conflicts. Either:
- Resolve them locally and complete the merge/rebase
- Leave the work uncommitted until resolved
[Allow pushing with conflicts: yes/no]
Good commit messages explain:
- What changed
- Why it changed (the context)
- How it addresses the issue
Bad messages: "fix", "update", "changes", "wip"
[Commit message format: freeform/imperative/conventional]
Each commit should represent one logical change:
- Don't mix refactoring with bug fixes
- Don't combine multiple features
- Keep it small enough to describe in one sentence
[Max lines per commit: number or leave blank]
✓ Add user authentication
✓ Fix login redirect loop
✗ Added user authentication
✗ Fixed the login bug
Work directly on the main branch or use short-lived feature branches:
- Main branch stays deployable
- Feature branches live for hours or days, never weeks
[Primary workflow: trunk-based/feature-branches/gitflow]
Names should describe the work:
feature/user-authenticationfix/login-redirect-loopdocs/readme-update
Avoid: work, tmp, fix1, branch
[Branch naming convention: prefix/description]
[List common prefixes to use: feature/, fix/, docs/, refactor/, test/]
Remove merged branches to keep the repo clean:
git branch -d branch-name[Auto-delete merged branches: yes/no]
[Default branch name: main/master]
A good PR:
- Addresses one concern
- Fits in a few hundred lines of diff
- Can be reviewed in 10-15 minutes
[Max files per PR: number or leave blank] [Max lines per PR: number or leave blank]
Include:
- What the change does
- Why it's needed
- Links to related issues
- Any testing done
[Require linked issues: yes/no]
Sequence diagrams in PRs are high-signal for behavioral changes, noise for trivial ones.
Add a diagram when:
- Explaining async/multi-step workflows (API flows, event-driven architecture)
- Showing multi-service interactions or state machine changes
- The behavioral change is harder to explain in text than in visual form
Skip the diagram when:
- Pure refactors, data-only changes, simple CRUD, one-line fixes
Tool: Mermaid (renders natively in GitHub):
```mermaid
sequenceDiagram
participant Client
participant API
participant Queue
participant Worker
Client->>API: POST /process
API->>Queue: enqueue(job)
API-->>Client: 202 Accepted
Queue->>Worker: trigger(job)
**Rule of thumb:** Add a diagram when explaining the *behavior* takes more text than drawing the *interaction*.
[Use sequence diagrams in PRs: yes/no]
### Respond to Reviews Promptly
- Address feedback directly
- Don't take criticism personally
- Ask for clarification when needed
[Require review before merge: yes/no]
[Required approvals: number]
[Allow force pushes to protected branches: yes/no]
---
## AI Agent Collaboration
### Rules for AI Agents
1. **Never auto-commit without approval** - show diffs first
2. **Always fetch before starting work** - confirm state is current
3. **Reference task context** - include issue/reason in commits
4. **Defer to human judgment** - especially on merge decisions
5. **Show meaningful diffs** - not whitespace-only changes
[AI agents may auto-commit: yes/no]
[AI agents may push directly: yes/no]
### When Working With Others
- Check for recent commits from others before making changes
- Communicate what you're working on to avoid collisions
- Don't assume you're the only one modifying the repo
[Announce work in progress: yes/no]
---
## Repo Hygiene
### Maintain Thorough .gitignore
Keep the repo clean by ignoring:
- Build artifacts (`node_modules/`, `dist/`, `target/`)
- IDE files (`.vscode/`, `.idea/`)
- OS files (`.DS_Store`, `Thumbs.db`)
- Secrets and credentials (`*.env`, `secrets.json`)
[Add custom .gitignore entries here]
### Avoid Committing Large Files
- Use Git LFS for binary assets
- Don't commit dependencies (use package managers)
- Keep the repo clone fast
[Use Git LFS for: blank or list patterns]
### Never Commit Secrets
- Credentials belong in environment variables
- Use `.gitignore` to exclude config files with secrets
- Rotate exposed secrets immediately
[Secrets storage: env-variables/secret-manager/other]
---
## GitHub Features
### Branch Protection
Protect main branches by:
- Requiring review before merge
- Blocking force pushes
- Running CI checks
[Protected branches: list or main/master]
### Use GitHub Actions Wisely
- Keep workflows simple and fast
- Fail fast on important checks
- Cache dependencies when possible
[List CI workflows here]
### Use Copilot Instructions
Add repo-specific guidance in `.github/copilot-instructions.md` for code review and completion.
[Copilot instructions file: exists/does-not-exist]
---
## Summary
1. **Always know the current state** - fetch before working
2. **Commit meaningfully** - explain why, not just what
3. **Keep branches short-lived** - merge quickly, delete after
4. **Resolve conflicts fully** - never push broken state
5. **For AI agents** - confirm state, show diffs, defer to humans
## Project-Specific Git Rules
For repo-specific Git/GitHub conventions, add them to `meta/PROJECT.md` under a Git section. This file is project-owned and never overwritten by hub propagation.
Example:
```markdown
## Git Conventions
- Use conventional commits: `feat:`, `fix:`, `docs:`, `refactor:`
- Branch naming: `feature/description` or `fix/issue-number`
- Squash merge for feature branches