Skip to content

Lesson 3: Git Fundamentals & GitOps Foundations

🧠 The Concept (Explain Like I'm 5)

Traditional file saving is like overwriting a word document. If you break it, your past work is lost.

Git is a time machine that takes a cryptographic photograph (a commit) of your entire project whenever you tell it to. * You can branch off into parallel universes (branches). * You can experiment without breaking production. * You can merge universes together once tests pass.


🏒 The Enterprise Context (Why Platform Architects Care)

In modern Platform Engineering, Git is the Single Source of Truth. * Infrastructure as Code (IaC): Terraform state and modules live in Git. * GitOps (ArgoCD): You never run kubectl apply manually. ArgoCD watches a Git repository; when a commit merges, ArgoCD automatically reconciles your multi-cluster fleet. * If a cluster is destroyed by disaster, you can rebuild the entire cloud platform in minutes simply by pointing tools at your Git repository.


πŸ—ΊοΈ Visual Model: The 4 Stages of Git

flowchart LR
    WD["<b>Working Directory</b><br/>Unsaved local edits"] -->|"git add ."| SA["<b>Staging Area (Index)</b><br/>Prepared for snapshot"]
    SA -->|"git commit -m"| LR["<b>Local Repository</b><br/>Committed in .git"]
    LR -->|"git push origin"| RR["<b>Remote (GitHub/GitLab)</b><br/>Shared enterprise repo"]
    RR -->|"git fetch / pull"| WD

🌳 The Enterprise Branching Workflow (Trunk-Based)

In high-velocity platform engineering teams, long-lived branches cause painful merge conflicts. Teams practice Trunk-Based Development:

gitGraph
    commit id: "Initial Commit"
    commit id: "Base Platform"
    branch feature/add-ingress
    checkout feature/add-ingress
    commit id: "Add Helm Chart"
    commit id: "Add Checkov Test"
    checkout main
    commit id: "Hotfix DNS"
    checkout feature/add-ingress
    merge main
    checkout main
    merge feature/add-ingress id: "PR-104-Merged"
    commit id: "Release v1.2.0"

πŸ’» Essential Git Commands for Platform Engineers

# 1. Create and switch to a new feature branch
git checkout -b feature/terraform-vpc-module

# 2. Check modified and untracked files
git status -s

# 3. Stage changes and commit with meaningful message
git add .
git commit -m "feat(vpc): add public/private subnet configuration with flow logs"

# 4. Keep your branch in sync with main before opening a Pull Request
git fetch origin
git rebase origin/main

# 5. Undo the last commit while keeping your local code changes intact
git reset --soft HEAD~1

# 6. View clean, visual commit graph in terminal
git log --oneline --graph --decorate -n 10

πŸ“ Knowledge Check

Question 1

In a GitOps workflow powered by ArgoCD, an engineer uses kubectl edit in production to fix an outage. Ten minutes later, the change mysteriously vanishes. What happened?

Question 2

What is the critical difference between git merge and git rebase, and why do platform teams prefer rebase for clean history?