12. Git in CI/CD — Automation & Deployment
Git in CI/CD — Automation & Deployment
Modern software teams do not manually deploy code. Every push to a Git repository triggers automated pipelines that test, build, and deploy code without human intervention. Understanding how Git integrates with CI/CD (Continuous Integration / Continuous Deployment) is essential for senior engineers and anyone working on teams that ship frequently.
⚙️ What CI/CD Actually Does
git pushGitHub ActionsPass / FailDocker imageAutoOn merge to main🐙 GitHub Actions — CI/CD Built Into GitHub
GitHub Actions is GitHub's built-in CI/CD system. It runs automated workflows in response to Git events (push, pull request, merge). Workflows are defined in YAML files in .github/workflows/:
The workflow YAML file lives at .github/workflows/ci.yml. A basic CI pipeline in YAML would:
- Trigger on every push and pull request
- Check out the code
- Set up Node.js
- Install dependencies (
npm install) - Run tests (
npm test) - Run linting (
npm run lint) - Build the app (
npm run build)
If any step fails, the PR cannot be merged (due to branch protection rules).
🔒 Branch Protection Rules
Branch protection rules on GitHub prevent developers from pushing directly to main or force-pushing over history. Configure these in: GitHub repo → Settings → Branches → Add rule. Required settings for a professional team:
- Require pull request before merging — No direct pushes to main
- Require at least 1 approval — Another developer must review before merge
- Require status checks to pass — CI pipeline must pass (tests green)
- Require branches to be up to date — Branch must include latest main before merge
- Do not allow force pushes — History is permanent; cannot be rewritten
🏷️ Git Tags & Releases
Tags mark specific commits as important (usually version releases). Create a lightweight tag:
Create an annotated tag (with a message and tagger info):
Push tags to remote (they don't push automatically with git push):
List all tags:
Checkout a specific version to inspect it:
On GitHub, tags automatically create a Release page where you can attach release notes and downloadable build artefacts.
Knowledge Check
Ready to test your understanding of 12. Git in CI/CD — Automation & Deployment?