Skip to content

Instantly share code, notes, and snippets.

@mohashari
Created March 14, 2026 15:13
Show Gist options
  • Select an option

  • Save mohashari/ca37b967b005c0131275a64d94a53585 to your computer and use it in GitHub Desktop.

Select an option

Save mohashari/ca37b967b005c0131275a64d94a53585 to your computer and use it in GitHub Desktop.
Code snippets — Git Workflow Best Practices
feature/oauth-google-login
fix/order-status-not-updating
chore/upgrade-postgres-16
experiment/grpc-migration-poc
fix(payments): handle race condition in concurrent charge requests
Two simultaneous charge requests for the same order could both
succeed if they ran concurrently. Added an idempotency key check
using a Redis distributed lock before processing payment.
Fixes: #482
# Squash WIP commits before review
git rebase -i origin/main
# In the editor, squash/fixup noisy commits:
pick abc1234 feat(auth): add JWT token generation
squash def5678 WIP
squash ghi9012 fix typo
squash jkl3456 actually fix it this time
# → becomes one clean commit
pick abc1234 feat(auth): add JWT token generation
main (always deployable)
└── feature/add-oauth-login
└── fix/user-not-found-on-edge-case
└── chore/upgrade-go-1-22
# See a visual branch graph
git log --oneline --graph --all
# Find which commit introduced a bug
git bisect start
git bisect bad HEAD
git bisect good v1.5.0
# Git will checkout commits; mark each as good/bad until found
git bisect good # or git bisect bad
# Find who last changed a line
git blame -L 42,55 src/auth/jwt.go
# Search commit messages
git log --grep="rate limiting" --oneline
# Find commits that changed a specific string
git log -S "calculateTax" --oneline
# Undo last commit but keep changes staged
git reset --soft HEAD~1
# Temporarily stash changes
git stash push -m "WIP: half-done oauth"
git stash pop
# Show changes from specific commit
git show abc1234
# Restore a deleted file from history
git checkout HEAD~3 -- src/utils/helper.go
main (production)
develop (integration)
└── feature/new-checkout
└── feature/user-profiles
release/2.0 (stabilization)
hotfix/critical-payment-bug → main + develop
# .git/hooks/pre-commit (make executable with chmod +x)
#!/bin/bash
set -e
echo "Running pre-commit checks..."
go fmt ./...
go vet ./...
golangci-lint run
go test ./... -short
echo "All checks passed!"
# Dependencies
node_modules/
vendor/
.venv/
# Build output
dist/
build/
*.o
*.a
*.so
# Secrets (NEVER commit these)
.env
.env.local
*.pem
*.key
credentials.json
secrets.yml
# IDE
.idea/
.vscode/
*.swp
# OS
.DS_Store
Thumbs.db

PR Template

What

Brief description of the change.

Why

Why is this change needed?

How to test

Steps for reviewers to verify the change.

Screenshots (if UI change)

Checklist

  • Tests added/updated
  • Documentation updated
  • No breaking changes (or noted in breaking changes section)
# Good commit messages
feat(auth): add refresh token rotation
fix(orders): prevent duplicate order creation on retry
perf(db): add index on orders.user_id for faster queries
refactor(user): extract email validation to separate function
# Bad commit messages
wip
fix bug
update code
asdfasdf
<type>(<scope>): <description>
[optional body]
[optional footer]
# .pre-commit-config.yaml
repos:
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-fmt
- id: go-vet
- id: golangci-lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment