Git & trunk-based workflows
Branching strategies, protected branches, release tagging — the substrate CI/CD is built on.
The mental model
Git is a **content-addressed database plus a set of sticky notes**. The database stores immutable snapshots — every commit is a full picture of the tree, identified by the hash of its contents, pointing back at its parent. Branches and tags are just sticky notes with a commit hash written on them. main is a sticky note that moves forward as you commit; a tag is a sticky note you promise never to move. HEAD is the note that says "you are here".
Once you internalise that, the scary commands stop being scary. git reset moves a sticky note. git merge writes a new snapshot with two parents. git rebase copies commits onto a different base — new hashes, new objects, old ones still in the database until garbage collection. Nothing that was committed is really lost for about 30 days, which is why git reflog rescues almost every "I destroyed the repo" panic.
**Trunk-based development** is the workflow that follows from wanting deployable snapshots constantly: everybody commits to short-lived branches off one trunk (main), merges within a day or two, and hides unfinished work behind feature flags rather than behind long-lived branches. The alternative — branches that live for weeks — trades a small daily merge cost for one enormous, high-risk merge later.
Why this matters for DevOps: CI/CD is built directly on top of these primitives. "Deploy on merge to main", "tag a release", "roll back to the previous tag", "who changed this line and why" — every one is a git operation with a pipeline attached.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision