Git & GitOps

Git records the history of every change. GitOps takes the next step and treats the repository as the source of truth for production itself.

Branch graph main · feature · release

Two developers edit the same file on Monday. They both save. Whoever saves second wins; whoever saves first loses their work. The team yells "who overwrote my changes?" across the office for the rest of the day.

That’s the world without Git. Everyone has a different copy of the truth, and the truth changes depending on whose backup you restore.

Git turns "whose copy is the right one?" into "which commit do we agree is the right one?" Every change is a tiny snapshot, signed by an author, with a parent. The repository is a graph of those snapshots. Multiple people can edit the same file at the same time, and Git knows how to combine the changes — or tell you when it can’t.

01What is Git, really?

Most engineers learn Git as a set of commands. That’s the wrong order. Learn the mental model first and the commands stop feeling like spells.

The simple version

Git is a tool that takes snapshots of your project, gives each snapshot a unique ID, and remembers the order they were taken in.

The technical version

Git is a content-addressable, distributed version control system. Each commit is an immutable snapshot of the working tree, identified by a SHA hash, with one or more parent commits. The history is a directed acyclic graph.

The team-shaped version

Git is the shared notebook your team writes the project in. Anyone can copy it, edit their copy, and propose their changes back — without losing anyone else’s work.

02Five words that explain Git

If you can use these five words confidently, you can read any Git tutorial and any repository’s history without panic.

  • commitA snapshot of the project at one point in time. Has an author, a message, a parent (or two for a merge), and a unique SHA.
  • branchA movable pointer to a commit. As you add commits to a branch, the pointer moves forward. Branches are cheap — make them freely.
  • HEAD"Where you are right now." Usually the tip of the branch you have checked out.
  • remoteAnother copy of the repository, usually on a server (origin). You push commits to it and fetch commits from it.
  • merge / rebaseTwo ways to combine work from one branch into another. Merge preserves history; rebase rewrites it.

03Three branching strategies — pick one

Every team eventually has an argument about how to use branches. Save the team a year by picking one of these three and writing it down on day one.

Trunk-based development

One long-lived branch (main). Everyone commits there many times a day, in tiny PRs. Unfinished work hides behind feature flags. Continuous Deployment thrives here.

Best for: elite teams that ship every day.

GitHub Flow

One main branch plus short-lived feature branches. Each feature branch opens a PR, runs CI, gets reviewed, merges to main, and deploys. Simple, forgiving, well-understood.

Best for: most teams. The friendly default.

GitFlow

main, develop, plus release/*, feature/* and hotfix/* branches. Heavy, but it maps cleanly to versioned products (mobile apps, SDKs, on-prem software).

Best for: teams that ship versions, not continuously.

04Merge vs rebase — the eternal debate

Both combine work from one branch into another. The result looks the same. The history doesn’t. Knowing which to use, and when, marks the engineer who has been bitten before.

git merge

  • Creates a merge commit. Two parents, preserves the real history.
  • Honest. The history shows exactly what happened.
  • Safe on shared branches. No one’s commits get rewritten.
  • Default for main. Use this when merging a finished feature.
vs

git rebase

  • Replays your commits on top of the target branch.
  • Linear. The history reads like a single line.
  • Dangerous on shared branches. Rewriting commits other people have based work on causes painful conflicts.
  • Default for your own feature branch. Keep it tidy before opening a PR.
i

The single rule

Never rebase a branch you have already pushed and someone else has pulled. Inside that rule, do whatever you like.

05The commands you’ll type today

Print this. Tape it to the monitor. These four groups cover the day-to-day of a professional Git user.

Inspect & switch

git status
git log --oneline --graph --decorate
git diff
git switch -c feat/payment

Save & sync

git add -p
git commit -m "feat(payment): add refund"
git push -u origin feat/payment
git pull --rebase

Combine

git fetch origin
git rebase origin/main
git merge --no-ff feat/payment
git cherry-pick <sha>

Undo (carefully)

git restore --staged file.js
git restore file.js
git revert <sha>        # safe public undo
git reset --hard <sha>  # local only, dangerous

06GitOps — when the repo becomes production

GitOps takes the version-control habit one step further: it makes Git not just the record of changes, but the cause of changes in production. You don’t kubectl apply from a laptop. You open a pull request. A controller does the rest.

Idea 01

Declarative manifests in Git

Everything that defines an environment — deployments, services, ingress, config, secrets references — lives in a Git repository, one folder per environment.

Idea 02

A controller watches the repo

Argo CD or Flux runs inside the cluster. They notice when the repo changes and apply the new state — or notice when the cluster drifts from the repo and apply it back.

Idea 03

Changes go through PRs

Want to bump an image tag in production? Open a PR. CI verifies it, a human approves it, the controller deploys it. The full audit trail is the Git log.

Idea 04

Rollback is git revert

Production goes wrong? Revert the commit. The controller picks up the older state and applies it. No special rollback scripts, no special tooling — the same workflow for forward and backward.

07Habits that keep history clean

A clean history is a kindness to your future self. These habits are small; the compounding effect is huge.

Anti-pattern
Long-running feature branches. A branch that lives for a month becomes a merge conflict factory. Keep branches short; rebase often; ship behind feature flags.
Anti-pattern
"WIP" or "fix typo" commit messages. They’re fine while you work, but squash them before merging. A clean history is the project’s memory; meaningless messages erase it.
Anti-pattern
Force-push to shared branches. Especially main. Other people have based commits on what was there; force-pushing rewrites their history too. Protect main in the platform settings.
Anti-pattern
Committing secrets. Once a secret hits Git, it’s effectively public — even after you delete it. Rotate the key, then scrub history. Use gitleaks as a pre-commit hook.
Healthy
Conventional commits. feat:, fix:, chore: in the message. Enables automated changelogs and semantic versioning — nearly free once the team gets in the habit.

08Putting it together

Take-aways

1. Git records snapshots (commits) and points at them with movable labels (branches). The history is a graph, not a line.

2. Pick one branching strategy — trunk-based, GitHub Flow or GitFlow — and write it on the wall.

3. Merge on shared branches; rebase your own. Never rewrite a branch someone else has pulled.

4. GitOps extends the discipline to production: the repository is the system, and a controller reconciles it.

Next chapter: the original CI / CD server, still everywhere in the enterprise — Jenkins.