A well-structured Git workflow is the backbone of productive software development. Whether you're a solo developer or part of a 50-person engineering team, these Git and GitHub practices will keep your codebase clean, your deployments smooth, and your team happy.
Choosing a Branching Strategy
GitHub Flow (Simplest)
Perfect for continuous deployment teams. Only has a main branch — all work happens on feature branches:
# Create a feature branch
git checkout -b feature/add-login-api main
# Make changes, commit, push
git add .
git commit -m "feat: add login API endpoint"
git push origin feature/add-login-api
# Open a PR on GitHub → merge to main → deploy
Git Flow (For Releases)
Best for projects with scheduled releases. Uses main, develop, feature/*, release/*, and hotfix/* branches:
main ──●──────────────●─────────●──
develop ────●──●──●──●─────●──●────
feature/auth └──●──●──●──┘
release/v1.0 └──●──●─┘
hotfix/login └─●─┘
Pull Request Best Practices
- Keep PRs small: Aim for under 400 lines changed. Large PRs rarely get thorough reviews.
- Write descriptive titles:
feat: add user authentication with OAuth2notfix stuff - Add context in description: Explain what, why, and how to test
- Link issues: Use
Closes #42to auto-close related issues - Request specific reviewers: Don't leave it to chance
Code Review Checklist
Before approving a PR, verify:
- ✅ Code follows project style guide
- ✅ Tests pass and new tests are added
- ✅ No debugging code or commented-out blocks
- ✅ Documentation is updated
- ✅ No security vulnerabilities (hardcoded secrets, SQL injection, etc.)
- ✅ Error handling is appropriate
- ✅ Performance implications are considered
Git Commit Convention (Conventional Commits)
<type>(<scope>): <description>
[optional body]
[optional footer(s)]
Types: feat, fix, docs, style, refactor, test, chore, perf, ci, build
feat(auth): add OAuth2 login flow
fix(api): handle null response from payment gateway
docs(readme): update installation instructions
perf(db): add index on user_email column
ci(deploy): add staging environment workflow
GitHub Actions CI/CD Integration
Automate your workflow with GitHub Actions. Here's a complete CI pipeline:
# .github/workflows/ci.yml
name: CI Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test
- run: npm run lint
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy to production
run: |
echo "Deploying to production server..."
# Add your deployment script here
Essential Git Commands Cheat Sheet
| Command | What it does |
|---|---|
git stash | Temporarily save uncommitted changes |
git rebase -i HEAD~5 | Interactive rebase — squash, reorder, edit commits |
git cherry-pick <hash> | Apply a specific commit to current branch |
git bisect | Binary search to find the commit that introduced a bug |
git log --oneline --graph | Visual commit history graph |
git blame <file> | See who changed each line and when |
git revert <hash> | Create a new commit that undoes a previous commit |
git reset --soft HEAD~1 | Undo last commit but keep changes staged |
GitHub Repository Best Practices
- README.md: Every repo needs a good README with setup instructions
- CONTRIBUTING.md: Guide for external contributors
- LICENSE: Always include a license file
- .gitignore: Don't commit node_modules, .env, build artifacts
- Branch protection: Require PR reviews before merging to main
- Dependabot: Enable automated dependency updates
Ready to level up? Check out our CI/CD Pipeline Guide and Custom WordPress Theme service.