RousselTMLEARNING

Article · DevOps: From Discovery to Expertise

Git for DevOps

1. Branching strategies #

Trunk-based or GitFlow.

Comparison #

Trunk-based development
Each branch lives less than a day; main stays deployable.
Trunk-based developmentGitFlow
Branchesmain + branches lasting a few hoursmain, develop, feature, release, hotfix
Integrationat least dailyat the end of the feature
Unfinished featureshidden behind feature flagsstay in their branch
Suited tocontinuous deployment, web servicesversions maintained in parallel, shipped software
Riskrequires solid automated testsmerge conflicts, late integration
Good practice: DORA research associates trunk-based development (fewer than three active branches, daily merging) with better delivery performance. Reserve GitFlow for products that maintain several versions.

2. Pull requests and reviews #

Reviewing fast and well.

A good pull request #

  • Small: fewer than 400 changed lines, a single topic.
  • A description that explains the why, with a link to the ticket.
  • The CI pipeline is green before human review.
  • Reviewed within the day: a review that waits several days is one more queue.

Protecting main #

  • Merge only through pull requests, at least one approval.
  • Mandatory CI statuses (tests, analysis, build).
  • Linear history (squash or rebase) and branch up to date before merging.
  • A CODEOWNERS file to automatically involve the right reviewers.
# CODEOWNERS
/infra/         @equipe-plateforme
/src/paiement/  @equipe-paiement
*.tf            @equipe-plateforme

3. Commits and versions #

A history readable by humans and tools.

Conventional commits #

feat(panier): ajouter le calcul des frais de port
fix(api): corriger le code HTTP en cas de stock vide
docs: documenter la variable DATABASE_URL
refactor!: renommer le champ client_id en customer_id

BREAKING CHANGE: l'API v1 n'accepte plus client_id

The prefix (feat, fix, docs, chore, refactor, test, ci) makes it possible to automatically generate the changelog and the next version number.

Semantic versioning #

ChangeVersionExample
FixPATCH1.4.2 → 1.4.3
New compatible feature (feat)MINOR1.4.3 → 1.5.0
Incompatible change (BREAKING CHANGE)MAJOR1.5.0 → 2.0.0
git tag -a v1.5.0 -m "v1.5.0"
git push origin v1.5.0
git describe --tags            # version la plus proche
git log v1.4.0..v1.5.0 --oneline --no-merges   # changements entre deux versions

Hooks and tools #

# .git/hooks/commit-msg : refuser un message non conventionnel
#!/usr/bin/env bash
grep -qE '^(feat|fix|docs|chore|refactor|test|ci|perf|build)(\(.+\))?!?: .+' "$1" || {
  echo "Message non conventionnel : type(portée): description" >&2; exit 1; }

As a team, hooks are shared with pre-commit (formatting, lint, secret detection) and versions and changelog are generated with semantic-release or release-please in the pipeline.

4. Fixing without panicking #

Rescue commands.

Commands #

git revert <sha>             # annuler un commit publié (crée un commit inverse)
git commit --amend           # corriger le dernier commit non poussé
git rebase -i HEAD~3         # réorganiser ses commits locaux avant la PR
git reflog                   # retrouver un commit « perdu »
git bisect start ; git bisect bad ; git bisect good v1.4.0   # trouver le commit fautif
git stash ; git stash pop

Golden rule #

Common mistake: Never rewrite (rebase, push --force) the history of a shared branch such as main: use git revert. If a force push is needed on your own branch, prefer --force-with-lease.

📄 Git for DevOps: branches, code reviews and versions →

My progress

  • ⏱ Estimated time : ≈ 6 min

Sign in to track your progress and take notes. Sign in

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

DevOps best practices: culture, CI/CD, infrastructure as code and measurement

DevOps best practices: culture and collaboration, continuous integration and delivery, trunk-base...

Git Sync in Grafana: version dashboards in GitHub

Sync Grafana dashboards and folders with a GitHub repository: prerequisites, token, setup in Admi...

The wall of confusion

The 'wall of confusion' is a metaphor often used in a DevOps context to describe the cultural, or...

Platform engineering, FinOps and AI: the new frontiers of DevOps

Understand how DevOps is evolving: platform engineering and internal developer platforms (IDP), g...

Infrastructure as Code and GitOps: Terraform, Ansible and Argo CD

Manage infrastructure as code: declarative or imperative, Terraform (providers, state, plan, modu...

Observability, SRE and incident management for DevOps teams

Operate what you ship: metrics, logs and traces, golden signals, SLIs, SLOs and error budgets, ac...

DevOps variants: understanding how engineering culture has evolved

Discover the different flavors of DevOps: DevSecOps, AIOps, NoOps, GitOps and FinOps. Understand ...

End-to-end CI/CD (1/5): principles and anatomy of a pipeline

Understand end-to-end CI/CD: continuous integration, continuous delivery and continuous deploymen...

End-to-end CI/CD (2/5): continuous integration, testing and quality

Succeed with continuous integration: the test pyramid, unit, integration, contract and end-to-end...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!