Archive · DevOps

A Git Workflow That Teams Can Follow

Short-lived branches, small pull requests and the modern switch and restore commands.

1 min read

  • Git 2.36
  • GitHub

Most DevOps practice starts with version control. A simple, effective flow:

flowchart LR
  M[main branch] --> F[feature branch]
  F --> PR[Pull request and review]
  PR --> CI[Automated checks]
  CI --> M
git switch -c feature/health-endpoint     # create and move to a branch
git add -p                                # stage in small, reviewable pieces
git commit -m "Add /health endpoint"
git push -u origin feature/health-endpoint
git restore --staged file.txt             # unstage
git switch main && git pull --rebase

git switch and git restore (Git 2.23 and later) split up the overloaded git checkout.

Habits that help: keep branches short-lived (days, not weeks), keep pull requests small, protect main so it needs a review and passing checks, and write commit messages that say why. Never commit secrets; if one slips in, rotate it, since removing it from history does not make it safe again.