| name | git-workflow |
| description | Git branching strategy, commit messages, PR workflow, conflict resolution. Use when setting up a branching strategy, writing commit messages, creating pull requests, or resolving merge conflicts. |
Git Workflow
Branching Strategy (GitHub Flow)
main ← production-ready at all times
└── feature/add-user-export ← feature branches (short-lived)
└── fix/login-rate-limit ← bug fix branches
└── chore/upgrade-dependencies ← maintenance
└── refactor/extract-auth-module ← refactoring
Rules:
main is protected — no direct pushes
- Every change goes through a PR
- PRs require at least 1 approval
- CI must pass before merge
- Branches are deleted after merge
Branch Naming
feature/user-profile-page
feature/export-orders-xlsx
fix/refresh-token-cookie-samesite
fix/n-plus-one-users-query
chore/update-nestjs-10
refactor/extract-payment-service
docs/add-api-endpoints-readme
test/add-auth-integration-tests
release/v2.1.0
johns-branch
fix1
JIRA-1234
wip
Commit Messages
<type>(<scope>): <short description>
<optional body — wrap at 72 chars>
<optional footer: BREAKING CHANGE or fixes #issue>
Types:
feat — new feature
fix — bug fix
refactor — code change that neither fixes a bug nor adds a feature
perf — performance improvement
test — adding or correcting tests
docs — documentation only
chore — build process, tooling, dependencies
ci — CI/CD config changes
Examples:
git commit -m "feat(auth): add JWT refresh token rotation"
git commit -m "fix(users): prevent email enumeration on login"
git commit -m "refactor(orders): extract payment processing to dedicated service"
git commit -m "perf(queries): add index on orders.user_id column"
git commit -m "test(auth): add integration tests for token expiry flow"
git commit -m "fix(uploads): reject files larger than 5MB
Previously the file size limit was only enforced on the frontend.
An attacker could bypass this by posting directly to the API.
Added multer limits and a guard to enforce 5MB server-side.
Fixes #142"
git commit -m "fix bug"
git commit -m "WIP"
git commit -m "asdfgh"
git commit -m "changes"
Creating a PR
git checkout main
git pull origin main
git checkout -b feature/user-export
git add src/users/users.service.ts src/users/dto/export.dto.ts
git commit -m "feat(users): add CSV export endpoint"
git add src/users/users.service.spec.ts
git commit -m "test(users): add unit tests for CSV export"
git push -u origin feature/user-export
gh pr create \
--title "feat(users): add CSV export endpoint" \
--body "$(cat <<'EOF'
## What
Adds a new endpoint GET /users/export.csv that returns all users as CSV.
## Why
Requested by ops team for bulk user management workflows. Fixes #89.
## Testing
- [ ] Unit tests added (users.service.spec.ts)
- [ ] Tested locally with 10k users
- [ ] Response headers verified in browser download
## Breaking Changes
None — new endpoint only.
EOF
)"
Keeping Your Branch Updated
git fetch origin
git rebase origin/main
git merge origin/main
Resolving Merge Conflicts
git status
code .
git add src/users/users.service.ts
git rebase --continue
git commit
Conflict marker anatomy:
<<<<<<< HEAD (your branch)
function getUserById(id: string) {
return this.repo.findOne({ where: { id } })
=======
async function getUserById(id: number) {
return this.repo.findOne({ where: { id }, relations: ['profile'] })
>>>>>>> origin/main
async function getUserById(id: string) {
return this.repo.findOne({ where: { id }, relations: ['profile'] })
}
Git Commands Reference
git status
git diff
git diff --staged
git log --oneline -10
git log --graph --oneline
git add <file>
git add -p
git reset HEAD <file>
git commit -m "message"
git commit --amend
git branch
git branch -d feature/done
git checkout -
git stash
git stash pop
git fetch origin
git push -u origin branch
git push --force-with-lease
git restore <file>
git reset --soft HEAD~1
git reset --mixed HEAD~1
git revert HEAD
Tagging Releases
git tag -a v1.2.0 -m "Release v1.2.0 — adds user export feature"
git push origin --tags
gh release create v1.2.0 \
--title "v1.2.0 — User Export" \
--notes "$(cat CHANGELOG.md)" \
--target main
.gitignore Essentials
# Node
node_modules/
dist/
build/
.next/
# Env files
.env
.env.local
.env.*.local
!.env.example # keep example file
# IDE
.vscode/settings.json
.idea/
*.iml
# OS
.DS_Store
Thumbs.db
# Logs
*.log
npm-debug.log*
pnpm-debug.log*
# Test artifacts
coverage/
playwright-report/
test-results/
# Generated
*.d.ts.map
Forbidden Patterns
- Never push directly to
main — always go through a PR
- Never force push to
main or shared branches
- Never commit
.env files — add them to .gitignore immediately
- Never use
git add . without reviewing what's staged (git diff --staged)
- Never amend or rebase commits that have already been pushed to a shared branch
- Never use
--no-verify to skip pre-commit hooks — fix the underlying issue
- Never commit generated files (dist/, .next/, coverage/) — add to .gitignore
- Never merge a PR without CI passing