Chapter 02
Git workflows
Everything in DevOps, from app code to infrastructure and pipeline definitions, lives in Git and changes through reviewed commits.
Branches and pull requests
Also called PR, merge request, MR, pull request, branch
- What
- A branch is a movable pointer to a line of commits. A pull request proposes merging a branch, runs CI checks and collects review before the change lands.
- Why
- Pull requests are where changes are tested and reviewed, and branch protection rules make that mandatory for the main branch.
git switch -c fix/nginx-timeout
git add nginx.conf
git commit -m "Raise proxy timeout for uploads"
git push -u origin fix/nginx-timeoutMerge vs rebase
Also called rebase
- What
git mergejoins histories with a merge commit.git rebasereplays your commits on top of another branch, giving a straight line of history.- Why
- Rebasing a feature branch onto main before merging keeps history readable. Merging preserves exactly what happened.
Watch out
Rebasing a branch others have pulled rewrites shared history; use git push --force-with-lease, never plain --force, and only on your own branches.
Trunk-based development
Also called GitFlow
- What
- Everyone merges small changes into one main branch at least daily, hiding unfinished work behind feature flags. GitFlow instead keeps long-lived develop and release branches.
- Why
- Short-lived branches mean fewer merge conflicts and fit continuous delivery. Most teams with CI/CD have moved to trunk-based work.
Undoing changes: revert vs reset
- What
git revertadds a new commit that undoes an earlier one.git resetmoves the branch pointer back, discarding or unstaging commits.git restorediscards file changes.- Why
- On shared branches revert is safe because it does not rewrite history. Reset is for local commits that nobody else has.
Watch out
Running git reset --hard on uncommitted work: it is gone. git reflog can recover lost commits, but not changes never committed.
.gitignore and secrets in Git
Also called gitignore, committed secrets, secrets in Git
- What
.gitignorelists files Git should not track, such as.env, build output and Terraform state. Once a secret is committed, it stays in history even after deletion.- Why
- Leaked keys in public repos are found by bots within minutes. Prevention is far cheaper than cleanup.
Watch out
Deleting a leaked key from the latest commit and moving on: rotate the key immediately, then clean history.