level 07 / git-and-branching
Git & Branching Strategies
Master Git workflows and branching strategies that support reliable test automation in CI.
Why Git Matters for Test Automation
Tests live in the same repo as source code. Poor Git hygiene causes flaky CI, merge conflicts in test files, and unreviewable PRs. Test automation engineers need fluent Git.
Essential Git Commands
# Status and inspection
git status # what changed
git log --oneline --graph # compact history
git diff HEAD~1 # diff against last commit
git show HEAD:e2e/smoke.spec.ts # file at a specific commit
# Stash — park work in progress
git stash push -m "wip: fixing login test"
git stash list
git stash pop
# Reset — undo staged or committed changes
git reset HEAD~1 --soft # undo commit, keep changes staged
git reset HEAD~1 --mixed # undo commit, unstage changes
git restore src/tests/auth.spec.ts # discard file changes
Branching Strategies
GitHub Flow (recommended for most teams)
main ──────────────────────────────────────────► production
│ │
└─ feature/add-auth-tests ───►│ PR → merge
- Branch from
main - Commit tests + implementation together
- Open PR — CI runs tests
- Merge to
mainonly when CI green
Gitflow (release-heavy projects)
main ─────────────────────────────────► stable releases
develop ──────────────────────────────► integration branch
│ │
└─ feature/tests ──►│ merge to develop
│
release/1.2 ──► hotfix if needed
Trunk-Based Development (CI/CD optimised)
All developers commit to main daily. Feature flags gate incomplete features. Tests must pass on every commit — no long-lived branches.
Conventional Commits for Tests
# Test-specific commit types
git commit -m "test: add auth flow e2e tests"
git commit -m "test: fix flaky cart checkout test"
git commit -m "test: update POM for new nav structure"
git commit -m "ci: add playwright shard config"
git commit -m "fix: correct locator for submit button"
PR Best Practices
# Before raising a PR
git fetch origin main
git rebase origin/main # rebase onto latest main
npx playwright test --project=chromium # run tests locally
# Squash noisy WIP commits
git rebase -i origin/main # interactive squash
PR checklist for test automation:
- Tests pass locally in CI configuration
- No hardcoded waits (
waitForTimeout) - New tests follow existing naming convention
storageState/ fixtures documentedplaywright.config.tschanges reviewed
.gitignore for Playwright Projects
# Test outputs
test-results/
playwright-report/
blob-report/
# Auth state (contains cookies — never commit)
playwright/.auth/
# Environment
.env
.env.local
# Build
dist/
node_modules/
Git Hooks for Test Quality
# .husky/pre-push — run tests before pushing
#!/bin/sh
npx playwright test --project=chromium e2e/smoke.spec.ts
Install: npm install --save-dev husky && npx husky install