Git & Version Control Standards
Git & Version Control Standards
Section titled “Git & Version Control Standards”1. Repository Structure
Section titled “1. Repository Structure”Branch Strategy
Section titled “Branch Strategy”- Main Branch:
main(ormasterfor legacy). Protected branch. All production code. - Development Branch:
develop(optional). Integration branch for features. - Feature Branches:
feature/description(e.g.,feature/user-authentication) - Bug Fixes:
fix/description(e.g.,fix/email-validation) - Hotfixes:
hotfix/description(e.g.,hotfix/security-patch) - Releases:
release/version(e.g.,release/1.2.0)
Branch Naming
Section titled “Branch Naming”- Format:
type/description(kebab-case) - Types:
feature,fix,hotfix,release,refactor,docs,test - Description: Concise, descriptive (3-5 words)
2. Commit Messages
Section titled “2. Commit Messages”Conventional Commits Format
Section titled “Conventional Commits Format”<type>(<scope>): <subject>
<body>
<footer>Commit Types
Section titled “Commit Types”- feat: New feature
- fix: Bug fix
- docs: Documentation changes
- style: Code style changes (formatting, missing semicolons)
- refactor: Code refactoring (no functional changes)
- perf: Performance improvements
- test: Adding or updating tests
- chore: Maintenance tasks (dependencies, build config)
- ci: CI/CD changes
- build: Build system changes
Commit Guidelines
Section titled “Commit Guidelines”- Subject: Imperative mood, 50 characters or less, no period
- Body: Explain “what” and “why”, wrap at 72 characters
- Footer: Reference issues/PRs:
Closes #123,Fixes #456 - Scope: Optional, indicates area of change (e.g.,
domain,api,ui)
Examples
Section titled “Examples”feat(domain): add user email validation
Implement RFC 5322 compliant email validation in Email value object.Rejects invalid formats at domain boundary to fail fast.
Closes #123fix(api): handle null response in user endpoint
Return 404 instead of 500 when user not found. Prevents servererrors from propagating to client.
Fixes #4563. Commit Best Practices
Section titled “3. Commit Best Practices”Atomic Commits
Section titled “Atomic Commits”- One Logical Change: Each commit should represent one complete, logical change
- Small Commits: Prefer multiple small commits over one large commit
- Testable: Each commit should leave the codebase in a working state
Commit Frequency
Section titled “Commit Frequency”- Regular Commits: Commit frequently (at least daily during active development)
- Logical Units: Commit when a logical unit of work is complete
- Before Break: Commit before leaving work for extended periods
What to Commit
Section titled “What to Commit”- Source Code: All source code, tests, and configuration
- Documentation: README, docs, comments
- Configuration: Build files, CI config, editor configs
- Dependencies: Lock files (package-lock.json, Cargo.lock, etc.)
What NOT to Commit
Section titled “What NOT to Commit”- Secrets: API keys, passwords, tokens, credentials
- Build Artifacts: Compiled binaries,
dist/,build/,target/ - Dependencies:
node_modules/,venv/,.envfiles - IDE Files:
.idea/,.vscode/(unless project-specific settings) - OS Files:
.DS_Store,Thumbs.db
4. Git Workflow
Section titled “4. Git Workflow”Feature Development
Section titled “Feature Development”- Create feature branch from
mainordevelop - Make atomic commits with descriptive messages
- Push branch regularly (at least daily)
- Open Pull Request when feature is complete
- Address review feedback with additional commits
- Squash commits if requested during review
- Merge via Pull Request (no direct pushes to main)
Pull Request Process
Section titled “Pull Request Process”- Title: Follow conventional commit format
- Description: Explain what, why, and how. Include screenshots for UI changes
- Size: Keep PRs focused and reviewable (< 400 lines when possible)
- Tests: Include tests for new features and bug fixes
- Documentation: Update documentation for user-facing changes
- CI: All CI checks must pass before merge
Code Review
Section titled “Code Review”- Required: At least one approval before merge
- Response Time: Review within 24-48 hours
- Feedback: Be constructive and specific
- Approval: Approve only when code meets standards
Merge Strategy
Section titled “Merge Strategy”- Squash and Merge: Preferred for feature branches (clean history)
- Merge Commit: Use for important features (preserve branch context)
- Rebase: Use for keeping feature branches up to date (avoid merge commits)
5. Tagging and Releases
Section titled “5. Tagging and Releases”Semantic Versioning
Section titled “Semantic Versioning”Format: MAJOR.MINOR.PATCH (e.g., 1.2.3)
- MAJOR: Breaking changes
- MINOR: New features (backward compatible)
- PATCH: Bug fixes (backward compatible)
Tagging
Section titled “Tagging”- Format:
v1.2.3(prefixed withv) - Annotated Tags: Use annotated tags for releases:
git tag -a v1.2.3 -m "Release 1.2.3" - Release Notes: Include release notes in tag message or GitHub release
Release Process
Section titled “Release Process”- Update version in code and
CHANGELOG.md - Create release branch:
release/v1.2.3 - Final testing and bug fixes
- Merge to
mainand tag:git tag -a v1.2.3 - Push tag:
git push origin v1.2.3 - Create GitHub/GitLab release with notes
- Merge back to
developif applicable
6. Git Configuration
Section titled “6. Git Configuration”Required Settings
Section titled “Required Settings”# User identificationgit config --global user.name "Your Name"git config --global user.email "your.email@example.com"
# Default branch namegit config --global init.defaultBranch main
# Push behaviorgit config --global push.default simplegit config --global push.autoSetupRemote true
# Pull behaviorgit config --global pull.rebase false # Use merge by defaultRecommended Settings
Section titled “Recommended Settings”# Color outputgit config --global color.ui auto
# Editorgit config --global core.editor "code --wait" # VS CodeGit Aliases
Section titled “Git Aliases”Git aliases provide shortcuts for common operations. The project standards include an automated setup script (scripts/setup-git-aliases.sh) that configures the following aliases.
Core Workflow Aliases
Section titled “Core Workflow Aliases”git co <branch>- Checkout a branchgit cob <branch>- Create and checkout new branch (checkout -b)git kick "message"- Create empty commit (commit --allow-empty -m)git up- Fetch and rebase against origin/maingit refresh-main- Reset local main branch to match origin/main (creates temp branch if on main, deletes local main, checks out origin/main, cleans up)git st- Statusgit br- List branchesgit cm "message"- Commit with message (commit -m)git ca- Amend last commit (commit --amend)git cane- Amend without editing message (commit --amend --no-edit)git unstage- Unstage files (reset HEAD --)git undo- Undo last commit, keep changes (reset --soft HEAD^)
Log and History Aliases
Section titled “Log and History Aliases”git last- Show last commit (log -1 HEAD)git lg- Pretty log graph (log --oneline --decorate --graph --all)git ll- Last 10 commits (log --oneline --decorate -10)git recent- Show reflog
Diff Aliases
Section titled “Diff Aliases”git diffc- Show staged changes (diff --cached)git diffst- Show staged changes (alternative:diff --staged)git who- Show blame (blame)
Branch Management Aliases
Section titled “Branch Management Aliases”git branches- List all branches (branch -a)git ls- List most recently edited branches in reverse chronological order (branch --sort=-committerdate)git brm- Delete branches that are gone from remotegit cleanup- Clean up remote-tracking branches
Pull/Push Aliases
Section titled “Pull/Push Aliases”git pullr- Pull with rebase (pull --rebase)git pushf- Push with force-lease (push --force-with-lease)git pushu- Push and set upstream (push -u origin HEAD)
Feature Branch Helpers
Section titled “Feature Branch Helpers”git feat <name>- Create feature branch (feature/<name>)git fix <name>- Create fix branch (fix/<name>)git hotfix <name>- Create hotfix branch (hotfix/<name>)
Stash Aliases
Section titled “Stash Aliases”git stashlist- List stashes (stash list)git stashpop- Pop latest stash (stash pop)git stashapply- Apply latest stash (stash apply)
Convenience Aliases
Section titled “Convenience Aliases”git aliases- List all configured aliasesgit amend- Amend last commit without editing (commit --amend --no-edit)git save- Stage all and commit with “WIP” messagegit wip- Stage all and commit with “WIP” message
Automatic Setup
Section titled “Automatic Setup”To automatically configure all aliases, run:
# From standards repository./scripts/setup-git-aliases.sh
# Or as part of project setup./.standards/scripts/setup-git-aliases.shThe setup script will:
- Check for existing aliases and prompt before overwriting
- Configure all recommended aliases
- Provide feedback on what was configured
Manual Configuration
Section titled “Manual Configuration”If you prefer to configure aliases manually:
# Core aliasesgit config --global alias.st statusgit config --global alias.co checkoutgit config --global alias.cob 'checkout -b'git config --global alias.kick 'commit --allow-empty -m'git config --global alias.up '!git fetch origin && git rebase origin/main'
# View all aliasesgit config --global --get-regexp alias7. Git Hooks
Section titled “7. Git Hooks”Pre-commit Hook
Section titled “Pre-commit Hook”- Linting: Run linters (ESLint, Pylint, Clippy)
- Formatting: Auto-format code (Prettier, Black, rustfmt)
- Tests: Run fast unit tests
- Validation: Check commit message format
Pre-push Hook
Section titled “Pre-push Hook”- Tests: Run full test suite
- Type Checking: Run type checkers (TypeScript, mypy)
- Build: Verify project builds successfully
Commit-msg Hook
Section titled “Commit-msg Hook”- Format Validation: Ensure commit messages follow conventional format
- Length Check: Validate subject line length
Implementation
Section titled “Implementation”Use tools like:
- Husky (Node.js)
- pre-commit (Python)
- git-hooks (Rust)
- Custom shell scripts
8. .gitignore Patterns
Section titled “8. .gitignore Patterns”Language-Specific
Section titled “Language-Specific”Python:
__pycache__/*.py[cod]*$py.class*.so.Pythonvenv/env/.venvNode.js:
node_modules/npm-debug.log*yarn-debug.log*yarn-error.log*.pnpm-debug.log*dist/build/Rust:
target/Cargo.lock # For libraries, not applicationsJava:
*.class*.jar*.war*.ear.gradle/build/Test / coverage output
Section titled “Test / coverage output”Ignore generated coverage reports so they are never committed:
coverage/Common tools that write here: Vitest, Jest, pytest, Istanbul/c8, lcov. Projects using the standards setup or install scripts get this pattern added automatically.
General
Section titled “General”# Environment.env.env.local.env.*.local
# IDE.idea/.vscode/*.swp*.swo*~
# OS.DS_StoreThumbs.db
# Logs*.loglogs/9. Large Files and Git LFS
Section titled “9. Large Files and Git LFS”Git LFS
Section titled “Git LFS”Use Git LFS for:
- Binary files > 100MB
- Media files (images, videos)
- Compiled binaries
- Database dumps
Configuration
Section titled “Configuration”git lfs installgit lfs track "*.psd"git lfs track "*.zip"10. Branch Lifecycle
Section titled “10. Branch Lifecycle”Cleanup After Merge
Section titled “Cleanup After Merge”Branches MUST be deleted — both local and remote — immediately after their PR is merged or closed. Do not accumulate stale branches.
- PR merge: Enable “Automatically delete head branches” in GitHub repo settings. This handles the remote branch. Delete the local branch manually after merge.
- Squash merges: Squash-merged branches are not detected by
git branch --merged. Usegit branch -d <branch>(lowercase-d) which checks if the branch is fully merged; if it refuses, verify the work landed via PR, then usegit branch -D <branch>. - Worktrees: Remove the worktree before deleting its branch:
git worktree remove <path>thengit branch -D <branch>.
Naming Branches for Traceability
Section titled “Naming Branches for Traceability”Include enough context in the branch name to identify the work without checking the log:
feat/preview-scroll-optimization ✓ clear purposefix/sidebar-drag-crash ✓ clear purposeworktree-agent-a0939472 ✗ opaque, impossible to triage latertmp ✗ no contextcopilot/sub-pr-7 ✗ meaningless without the PRAgent-generated branches MUST follow the same type/description convention as human branches. Opaque IDs or numeric suffixes alone are not acceptable names.
Periodic Audit
Section titled “Periodic Audit”Run a branch audit at least every two weeks (or before starting a new feature):
# List local branches not on main, sorted by last commit dategit branch --no-merged main --format='%(committerdate:short) %(refname:short)' | sort
# List remote branches with no recent activity (>14 days)git for-each-ref --sort=committerdate --format='%(committerdate:short) %(refname:short)' refs/remotes/origin | head -20
# Delete local branches whose remote is gonegit fetch --prunegit branch -vv | grep ': gone]' | awk '{print $1}' | xargs -r git branch -DProjects using make SHOULD include a cleanup target:
branch-cleanup: ## Delete local branches whose remote tracking branch is gone @git fetch --prune @git branch -vv | grep ': gone]' | awk '{print $$1}' | xargs -r git branch -D @echo "Remaining branches:" && git branchBranch Limits
Section titled “Branch Limits”As a guideline, a repository should have fewer than 10 active branches at any time. If you have more, audit and clean up before creating new ones. This applies to both local and remote branches (excluding main).
Garbage Collection
Section titled “Garbage Collection”- Run
git gcperiodically (usually automatic). - After large cleanups, run
git gc --prune=nowto reclaim space immediately.
Security
Section titled “Security”- Secrets Scanning: Use tools like
git-secrets,truffleHog - History Rewriting: Avoid force-pushing to shared branches
- Access Control: Use branch protection rules (GitHub/GitLab)
Backup
Section titled “Backup”- Remote Repository: Always push to remote (GitHub, GitLab, etc.)
- Multiple Remotes: Consider backup remote for critical projects
- Regular Pushes: Push at least daily during active development