Learn › Git

Pull Requests and Protecting main: Code Review for Ops Teams

Run your automation repo like a professional team: good pull requests, useful reviews, CODEOWNERS, branch protection rules and required checks on GitHub.

Intermediate 10 min read
By Gopinath Karthikeyan

When scripts can restart services across hundreds of servers, a second pair of eyes is cheap insurance. Pull requests (PRs) give you that review – and branch protection makes sure nobody skips it, not even in a hurry.

Git feature branch and pull request flow into a protected main branch main main feature/fix-dns feature/fix-dns merge merge Pull request Pull request 1 git switch -c feature/fix-dns git switch -c feature/fix-dns 2 Commit small, clear changes சிறிய, தெளிவான commits 3 git push, then open a pull request git push, பிறகு pull request 4 Review + automatic checks pass Review + automatic checks pass 5 Merge into protected main Protected main-ல் merge
Work happens on a short-lived branch. A pull request gets review and automatic checks before the change is merged into main.மாற்றங்கள் ஒரு சிறிய branch-ல் நடக்கும். Pull request-ல் review, checks முடிந்த பிறகே main-ல் merge ஆகும்.

What a good pull request looks like

  • Small – one change, ideally under a few hundred lines. Big PRs get skimmed, not reviewed.
  • A clear title – “Disk report: warn at 20% instead of 15%”, not “updates”.
  • A description that answers:
    • What changes and why?
    • How was it tested (which server, what output)?
    • What’s the risk, and how do we roll back?
  • Linked ticket if your team uses them.

Add a template so every PR asks these questions. Create .github/pull_request_template.md:

## What and why

## How I tested it
- [ ] Ran with -WhatIf / in check mode
- [ ] Ran on a test server

## Risk and rollback

Reviewing a PR

A useful review checklist for automation code:

  1. Safety – could this hit more servers than intended? Is there a dry-run mode?
  2. Secrets – any password, token, IP or real hostname that shouldn’t be there?
  3. Error handling – what happens if one server is offline?
  4. Readability – would someone on-call at 3 a.m. understand it?
  5. Tests and checks – did the pipeline pass?

Comment on specific lines, explain why, and suggest a fix. Approve when it’s good enough to be safe – not when it’s how you would have written it.

Protect main

On GitHub: Settings → Branches → Add branch protection rule (or Rulesets) for main:

  • ✅ Require a pull request before merging
  • ✅ Require approvals – at least 1
  • ✅ Dismiss stale approvals when new commits are pushed
  • ✅ Require status checks to pass – e.g. your Jenkins or GitHub Actions lint/test job
  • ✅ Require conversation resolution
  • ✅ Do not allow bypassing the above settings (include administrators)
  • ❌ Allow force pushes – leave off

Now main only changes through reviewed, tested PRs.

CODEOWNERS – the right reviewers automatically

Create .github/CODEOWNERS:

# Path                 Owners
/ansible/              @your-org/windows-automation
/jenkins/              @your-org/ci-admins
/scripts/patching/     @your-org/patching-leads

Combined with Require review from Code Owners, a change to patching scripts can’t merge without the patching leads approving.

Merge strategies

GitHub offers three buttons:

  • Merge commit – keeps every commit plus a merge commit
  • Squash and merge – one tidy commit per PR (popular for ops repos)
  • Rebase and merge – commits added in a straight line

Pick one for the repo and stick with it.

FAQ

We’re a team of two – is this overkill? Branch protection and one required approval cost almost nothing and prevent the “quick fix straight to main” that breaks production on a Friday evening.

Who approves my PR if I’m on my own? Still use PRs and required checks – the automated lint and tests are your reviewer.

What’s next

Next: Repo layout and secrets hygiene for ops teams.

Practise this topic

Test yourself with free questions on this topic – instant answers and explanations.

Start practice questions

GitGitHubPull RequestsCode ReviewIntermediate

Gopinath Karthikeyan

Gopinath Karthikeyan – Windows Site Reliability Engineer with about 12 years in enterprise Windows Server infrastructure, and founder of WinOps Academy. YouTube · LinkedIn

More in Git