Lesson 3 — Git Workflows & Collaborative Delivery
Course: DevOps & Platform Engineering (devops) · Group: Data Engineering
Workplace: Northline (illustrative synthetic organisation)
Assumed environment: Git 2.39+ on Ubuntu 22.04 LTS (illustrative); GitHub used as the remote platform example — concepts apply to GitLab, Bitbucket, Gitea, and others. Basic Git operations (clone, add, commit, push, pull) are covered in Git Foundations #git1–#git8 and are prerequisites, not repeated here.
Status: approved
Learning objectives & deliverable
By the end of this lesson you will be able to:
- Describe and apply trunk-based development and feature-branch workflows, and explain when each is appropriate.
- Explain the three merge strategies (merge commit, squash merge, rebase) and choose between them.
- Configure and work within protected branch rules: required reviews, status checks, and push restrictions.
- Write clean, consistent commit messages following the Conventional Commits convention.
- Manage Git tags and apply semantic versioning (semver) naming conventions.
- Resolve a merge conflict systematically without discarding others' work.
- Safely roll back a bad change using
git revert(history-preserving) vsgit reset(history-rewriting). - Prevent secrets from entering a repository using pre-commit hooks and repository scanning.
Deliverable: A written branching strategy document (one A4 page or equivalent) for a fictional Northline service, specifying: branch naming conventions, merge strategy, protection rules, tag format, and one pre-commit secret-prevention control. Reviewed by teacher.
Prerequisites
| Concept | Where to learn it |
|---|---|
| Git fundamentals (clone, add, commit, push, pull, branch, merge basics) | Git Foundations #git1–#git8 |
| CI/CD delivery lifecycle | Lesson 1 — DevOps & Platform Engineering #devops1 |
| Shell scripting basics | Lesson 2 — Linux & Bash #devops2 |
| CI pipeline configuration | Lesson 4 — Continuous Integration #devops4 (forward reference) |
Lesson opener
In one line: In a team of ten engineers committing to the same repository, the branching strategy, merge discipline, and commit hygiene are the difference between a codebase that deploys confidently every day and one that locks up before every release.
Why it matters: Git basics (clone, add, commit, push) are covered in #git1–#git8. Enterprise Git work is everything that happens between those basics and production: the governance rules that prevent broken code from reaching main, the conflict-resolution skills that let teams work in parallel without stepping on each other, the rollback procedures that restore service when a deploy goes wrong, and the secrets-prevention controls that stop credentials from leaking into repository history. These are daily skills on any professional data engineering team.
Before this lesson: Complete Git Foundations #git1–#git8 and #devops2 (shell scripting, used in pre-commit hooks). #devops4 covers CI pipeline configuration that enforces the branch protections described here.
Northline's data-ingestion team had five engineers working on separate features for the Q3 release. Two of them modified the same Kafka consumer configuration file. Without agreed merge strategy and protected branch rules, the merge went wrong: one engineer's changes overwrote the other's entirely. The incorrect configuration reached staging and failed smoke tests. The team lost four hours diagnosing a conflict that should have been caught in a PR review. This lesson teaches the workflow that prevents that scenario.
1. Branch Strategies
1.1 Trunk-Based Development (TBD)
In trunk-based development, all engineers commit to a single shared branch (main or trunk) directly, or via very short-lived feature branches (merged within one working day). There is no long-running develop or release branch.
Characteristics:
- Feature branches live for hours, not weeks.
- Each merge triggers CI immediately.
- Feature flags control whether in-progress work is visible to users.
- All engineers are continuously integrating with each other's changes.
When TBD is appropriate: Teams with high test coverage, mature CI pipelines, and strong feature-flag infrastructure. It is the pattern behind elite DORA performers.
When TBD is difficult: Teams with long-running features that cannot be hidden behind flags, or with regulatory requirements for an explicit staging gate on every change.
1.2 Feature Branch Workflow
Engineers create branches from main for each feature or fix, work for days to weeks, and open a pull request when ready.
main ──────────────────────────────────────────►
\ /
feature/kafka-dlq ──── PR ──► mergeCharacteristics:
- PRs provide a natural code-review checkpoint.
- CI runs on every push to the feature branch.
- Risk: long-lived branches accumulate drift from
main; merges become expensive.
Northline convention: Feature branches are merged within 3 working days. Branches older than 5 days without activity are flagged for discussion in the daily standup.
1.3 Release Branches
A release branch is cut from main when a release is being stabilised. Only bug fixes and hotfixes are merged into it after the cut; new features continue on main.
main ──────────────────────────────────────────►
\
release/1.4.0 ──── hotfix/1.4.1 ──► tag v1.4.1When used at Northline: The streaming platform library (northline-common) uses release branches because multiple downstream services pin to specific minor versions. Application services use feature branches directly to main without release branches.
1.4 Northline Branch Naming Convention
| Type | Pattern | Example |
|---|---|---|
| Feature | feature/<jira-id>-<short-description> | feature/NL-2047-kafka-dlq |
| Bug fix | fix/<jira-id>-<short-description> | fix/NL-2089-null-schema |
| Hotfix (from release) | hotfix/<version>-<description> | hotfix/1.4.0-timeout |
| Release | release/<semver> | release/1.5.0 |
| Chore / dependency | chore/<description> | chore/update-confluent-deps |
2. Merge Strategies
When a feature branch is ready, there are three ways to integrate it into main. The choice affects history readability and blame accuracy.
2.1 Merge Commit (Standard Merge)
git checkout main
git merge --no-ff feature/NL-2047-kafka-dlqCreates a merge commit that has two parents: the tip of main and the tip of the feature branch. The full branch history is preserved.
main ──────────────M─────►
/|
feature ──A──B──C─Pros: Full history preserved; easy to revert the entire feature by reverting the merge commit.
Cons: History can become noisy with many small commits from the feature branch.
GitHub equivalent: The "Create a merge commit" button in the PR merge dialog.
2.2 Squash and Merge
All commits on the feature branch are squashed into one new commit on main.
git checkout main
git merge --squash feature/NL-2047-kafka-dlq
git commit -m "feat(kafka): add dead-letter queue support (NL-2047)"main ──────────────S─────►
(S contains A+B+C squashed)Pros: Clean, linear history on main; each feature is one atomic commit.
Cons: Individual branch commits are lost; harder to bisect if the single squashed commit is large.
When to use: Short-lived feature branches where intermediate commits are "WIP" or "fix typo" noise.
2.3 Rebase and Merge
Replays the feature branch commits on top of the current tip of main, creating new (different) commit SHAs.
git checkout feature/NL-2047-kafka-dlq
git rebase main
git checkout main
git merge --ff-only feature/NL-2047-kafka-dlqmain ──────────────A'──B'──C'─►
(A', B', C' are replayed commits with new SHAs)Pros: Linear history; individual commits are preserved; git bisect works cleanly.
Cons: Rewrites history; never rebase a branch that others are using. Requires force-push, which is dangerous on shared branches.
Northline policy: Squash merge is the default for feature branches to main. Rebase is permitted for personal cleanup before opening a PR, never after the PR is open.
2.4 Choosing a Strategy
| Strategy | History | Atomic revert | Safe for shared branches | Northline default |
|---|---|---|---|---|
| Merge commit | Full branch history | Yes (revert merge commit) | Yes | Library repos |
| Squash merge | Linear, one commit/feature | Yes (revert squash commit) | Yes | Application services |
| Rebase | Linear, original commits | Yes (revert each commit) | No | Pre-PR cleanup only |
3. Pull Requests — the Collaborative Review Gate
A pull request (PR) is a request to merge a branch, combined with a structured review and discussion interface. It is the primary quality gate before code reaches main.
3.1 Anatomy of a good PR
A PR description at Northline follows this template (stored in .github/pull_request_template.md — illustrative):
## What does this change do?
<!-- One paragraph: the change and why it is being made -->
## Linked ticket
<!-- e.g., NL-2047 -->
## How was it tested?
<!-- Unit tests added/updated: yes/no. Staging tested: yes/no. -->
## Checklist
- [ ] CI pipeline passes
- [ ] No secrets or credentials in the diff
- [ ] Documentation updated if behaviour changed
- [ ] Dependency changes reviewed for known vulnerabilitiesA PR that does not fill in the template is not ready for review.
3.2 Review etiquette
- Author: respond to all comments before requesting re-review; mark resolved threads only after addressing them.
- Reviewer: distinguish between "must fix before merge" (blocking) and "consider for future" (non-blocking). Use GitHub's "Request changes" vs "Comment" accordingly.
- Size: PRs over 500 lines of changed code are significantly harder to review effectively. Break large features into smaller, independently merge-able PRs.
3.3 Draft PRs
Opening a PR as a draft signals "this is not ready for review yet — I am sharing for visibility." CI still runs. Reviewers are not notified for review. This is useful for early feedback or WIP pipeline testing.
4. Protected Branches
Branch protection rules prevent direct pushes, enforce review requirements, and require CI to be green before merging.
4.1 Configuring protection (GitHub — illustrative)
On GitHub, branch protection is configured in: Repository → Settings → Branches → Add rule.
Northline's main branch protection rules:
| Rule | Setting |
|---|---|
| Require pull request before merging | Enabled; 1 required approving review |
| Require status checks to pass | Enabled; required checks: lint, unit-tests, dependency-scan |
| Require branches to be up to date before merging | Enabled |
| Restrict who can push to matching branches | Only repo-admins team |
| Do not allow bypassing the above settings | Enabled (prevents admin bypass) |
| Allow force pushes | Disabled |
| Allow deletions | Disabled |
Note: Exact rule names and options vary by platform version. Always verify current settings against your platform's documentation.
4.2 Status checks and CI integration
Protected branch status checks are satisfied by CI pipeline jobs. Each required check must report "success" before the merge button is enabled. Details in #devops4.
4.3 CODEOWNERS
The CODEOWNERS file (stored in .github/CODEOWNERS on GitHub) assigns automatic review requirements by directory or file pattern.
# .github/CODEOWNERS — illustrative
# Require data-eng-leads to review any changes to pipeline configuration
/config/pipeline/ @northline-internal/data-eng-leads
# Require platform-team to review Dockerfile changes
Dockerfile @northline-internal/platform-team
# Require security-team to review dependency files
requirements*.txt @northline-internal/security-teamWhen a PR touches a CODEOWNERS-governed file, the designated team is automatically added as a required reviewer.
5. Commit Hygiene — Conventional Commits
A consistent commit message format makes git log, automated changelogs, and bisect more useful. Northline uses the Conventional Commits convention.
5.1 Format
<type>(<scope>): <subject>
[optional body]
[optional footer(s)]Types:
| Type | When to use |
|---|---|
feat | A new feature |
fix | A bug fix |
chore | Dependency updates, tooling, build configuration |
docs | Documentation only |
test | Adding or updating tests |
refactor | Code restructure with no behaviour change |
perf | Performance improvement |
ci | Changes to CI configuration |
revert | Reverting a previous commit |
5.2 Good vs. bad commit messages
| Bad | Good |
|---|---|
fix stuff | fix(kafka): handle null schema in deserialiser (NL-2089) |
wip | (use a draft PR instead; WIP commits should not reach main) |
update deps | chore: update confluent-kafka to 2.3.1 (see NL-2102) |
JIRA-1234 | feat(ingestion): add dead-letter queue for poison messages (NL-2047) |
final final v2 | (this is a squash candidate before PR is opened) |
5.3 Committing atomically
Each commit should represent one logical change that leaves the codebase in a working state. A commit that both refactors a module and adds a new feature is harder to revert if either part causes a regression.
# Stage only the files relevant to the fix
git add src/consumer/deserialiser.py tests/test_deserialiser.py
# Leave the unrelated refactor staged separately
git add --patch src/consumer/router.py # interactive staging by hunk6. Tags and Semantic Versioning
Tags mark specific commits as significant points in history — typically releases.
6.1 Creating and pushing tags
# Lightweight tag (just a pointer to a commit)
git tag v1.5.0
# Annotated tag (recommended — stores tagger, date, and message)
git tag -a v1.5.0 -m "Release 1.5.0: add dead-letter queue support"
# Push a specific tag
git push origin v1.5.0
# Push all tags
git push origin --tags
# List tags
git tag -l
# Show tag details
git show v1.5.06.2 Semantic versioning (semver)
Semver format: MAJOR.MINOR.PATCH (e.g., 1.5.0).
| Component | Increment when | Example |
|---|---|---|
| MAJOR | Breaking API or behaviour change | 1.x.x → 2.0.0 |
| MINOR | New functionality, backwards-compatible | 1.4.x → 1.5.0 |
| PATCH | Backwards-compatible bug fix | 1.5.0 → 1.5.1 |
Pre-release identifiers: 1.5.0-rc.1, 1.5.0-beta.2.
Semver is a convention, not enforced by Git. It requires discipline and team agreement. Automated tools (e.g.,
semantic-release,standard-version) can increment version numbers from Conventional Commit messages — check current availability and pricing for your chosen tool.
6.3 Northline tag policy
- Application service tags:
v<semver>(e.g.,v1.5.0). - Library tags:
v<semver>— increment MAJOR for breaking changes to shared interfaces. - Do not tag commits that have not passed all CI checks.
- Tags are immutable at Northline: once pushed, a tag is never moved or deleted. If a release is pulled back, the tag remains and a new
v<next>tag is created after the fix.
7. Conflict Resolution
A merge conflict occurs when two branches have modified the same lines of the same file in incompatible ways.
7.1 Anatomy of a conflict marker
<<<<<<< HEAD (current branch)
kafka_broker = "kafka-broker.northline.internal:9092"
=======
kafka_broker = "kafka-broker-v2.northline.internal:9092"
>>>>>>> feature/NL-2047-kafka-dlq (incoming branch)The section between <<<<<<< HEAD and ======= is what is currently on your branch. The section between ======= and >>>>>>> is what is coming from the other branch. You must choose one, combine both, or write something different — then remove all conflict markers.
7.2 Systematic resolution workflow
# 1. Identify all conflicted files
git status
# 2. For each conflicted file, open it and resolve manually
# (or use a merge tool)
git mergetool # opens configured merge tool (e.g., vimdiff, VS Code)
# 3. After resolving, stage the resolved file
git add src/config/consumer.yml
# 4. Complete the merge
git commit # auto-populates merge commit message
# 5. Verify
git log --oneline --graph -107.3 Using VS Code as merge tool (illustrative)
Add to .gitconfig:
[merge]
tool = vscode
[mergetool "vscode"]
cmd = code --wait $MERGEDVS Code displays the conflict with "Accept Current Change", "Accept Incoming Change", and "Accept Both Changes" buttons. For complex conflicts, reading both changes carefully and writing a combined resolution manually is often more accurate than clicking "Accept Both".
7.4 Prevention
The best conflict-resolution strategy is to reduce the frequency of conflicts:
- Keep feature branches short-lived (merge within 1–3 days).
- Rebase your feature branch onto
mainbefore opening a PR:git fetch origin && git rebase origin/main. - Communicate in stand-up when two engineers are working in the same file.
8. Rollback and Revert
Two mechanisms exist for undoing changes in Git. They have very different safety profiles.
8.1 git revert — safe, history-preserving (use by default)
git revert creates a new commit that undoes the changes of a specified commit. The original bad commit remains in history; the revert commit is added on top.
# Revert a single commit by SHA
git revert abc1234 --no-edit # --no-edit uses default message
# Revert a merge commit (must specify which parent to revert to)
git revert -m 1 abc1234 # -m 1: keep the first parent (main line)
# Push the revert to the remote
git push origin mainWhy it is safe: History is preserved; the CI pipeline validates the revert commit before it reaches production; the action is fully auditable.
8.2 git reset — dangerous on shared branches
git reset moves the branch pointer backwards, discarding commits.
# Soft reset: discards commits but keeps changes staged
git reset --soft HEAD~1
# Mixed reset (default): discards commits, unstages changes
git reset HEAD~1
# Hard reset: DISCARDS commits AND all changes — irreversible
# ⚠️ DESTRUCTIVE: only use on your own local unshared branch
git reset --hard HEAD~1⚠️ Never use
git reset --hardor force-push on a branch that other engineers are using. It rewrites history; their local branches will diverge and they will lose work. Protected branches block force-push for this reason.
8.3 Northline rollback procedure
When a bad deploy is detected:
- In the platform portal: click Rollback (deploys the previous known-good image SHA — handled by the platform team's deployment tooling).
- If the bad code is already merged to
main: open a PR with agit revertof the merge commit. - CI runs on the revert commit; it merges after passing checks.
- The platform portal promotes the reverted build to production.
- Post-mortem is written within 48 hours (illustrative policy).
Direct git push --force to main is not available due to branch protection. The revert PR path is the only way.
9. Secrets Prevention
Credentials, API tokens, private keys, and passwords must never be committed to a repository. Once committed, they are in git history and may be exposed even if the file is later deleted. This section covers prevention controls; scanning for leaked secrets is covered in #devops4.
9.1 The risk
A committed secret (even in a deleted file, even in a private repository) should be treated as compromised immediately. History-rewriting to remove it is complex, error-prone, and does not help if the repository was cloned or a webhook triggered during the window of exposure.
9.2 Pre-commit hooks with pre-commit framework
The pre-commit framework (https://pre-commit.com) runs checks before every git commit. It is the most effective point to block secrets.
# Install pre-commit (illustrative — confirm current installation method at pre-commit.com)
pip install pre-commit
# Create .pre-commit-config.yaml in the repository root
# Example configuration:# .pre-commit-config.yaml — illustrative; pin versions before use
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.2 # pin to a specific version; check current releases
hooks:
- id: gitleaks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: detect-private-key
- id: check-added-large-files
args: ['--maxkb=500']
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
hooks:
- id: ruff
args: [--fix]# Install the hooks into the local .git/hooks directory
pre-commit install
# Run all hooks against all files (useful when adding to an existing repo)
pre-commit run --all-filesNote on versions: Pin hook versions (
rev:) to specific tags.rev: latestor floating refs can change behaviour without warning. Check each hook's repository for current stable releases.
9.3 .gitignore as a first line of defence
# Secrets and credentials
.env
.env.*
*.pem
*.key
secrets/
credentials/
# IDE and OS artefacts
.idea/
.vscode/settings.json
__pycache__/
*.pyc
.DS_Store
# Build artefacts
dist/
build/
*.egg-info/.gitignore prevents accidental staging; it does not scan for secrets in files that are not ignored. Both controls are needed.
9.4 What to do when a secret is committed
- Revoke the secret immediately. Do not wait. Rotate the token or key before doing anything else.
- Notify the relevant service owner or security team per your organisation's incident procedure.
- To remove from git history (use
git filter-repo— the current recommended tool;BFG Repo Cleaneris an alternative). History rewriting requires force-push and requires all collaborators to re-clone — treat it as a production incident, not routine cleanup. - If the repository is public or was ever public, assume the secret was harvested by automated scanners within seconds.
Do not use
git filter-branchfor this purpose; it is deprecated and error-prone. Usegit filter-repo(check current availability and installation at https://github.com/newren/git-filter-repo).
Worked Example A — Feature Branch to Production (Full Trace)
Feature: Add a dead-letter queue (DLQ) to the Kafka consumer to capture poison messages (ticket NL-2047).
# 1. Start from an up-to-date main
git checkout main
git pull origin main
# 2. Create a feature branch
git checkout -b feature/NL-2047-kafka-dlq
# 3. Develop. Write tests first (TDD). Make multiple commits.
git add src/consumer/dlq.py tests/test_dlq.py
git commit -m "feat(kafka): scaffold dead-letter queue handler (NL-2047)"
git add src/consumer/deserialiser.py
git commit -m "feat(kafka): route poison messages to DLQ on deserialization error"
git add docs/adr/0012-dlq-design.md
git commit -m "docs: add ADR-0012 for DLQ approach"
# 4. Before opening PR: rebase onto current main to reduce drift
git fetch origin
git rebase origin/main
# Resolve any conflicts here (see §7)
# 5. Push and open PR
git push origin feature/NL-2047-kafka-dlq
# Open PR on GitHub — fill in the PR template
# 6. CI runs automatically (GitHub Actions). Reviewer approves.
# 7. Squash and merge via GitHub UI
# Result: one commit on main — "feat(kafka): add dead-letter queue (NL-2047)"
# 8. Tag the release
git checkout main && git pull origin main
git tag -a v1.5.0 -m "Release 1.5.0: add dead-letter queue support (NL-2047)"
git push origin v1.5.0Worked Example B — Hotfix on a Release Branch
Scenario: stream-processor v1.4.0 is in production. A timeout regression is discovered. The fix must go to v1.4.x without pulling in unreviewed features currently on main.
# 1. Create a hotfix branch from the release tag
git checkout -b hotfix/1.4.0-timeout v1.4.0
# 2. Apply the minimal fix
git add src/consumer/kafka_client.py
git commit -m "fix(kafka): increase consumer timeout to 30s (NL-2156)"
# 3. Tag the hotfix release
git tag -a v1.4.1 -m "Hotfix 1.4.1: increase consumer timeout"
git push origin hotfix/1.4.0-timeout v1.4.1
# 4. Also apply the fix to main (so future releases include it)
git checkout main
git cherry-pick <sha-of-fix-commit>
git push origin mainThis preserves the stability of the v1.4.x line while keeping main current.
Failure Scenario — Rebase Disaster on a Shared Branch
Symptom: After a rebase, a colleague's git pull fails with "refusing to merge unrelated histories" and their local commits appear to be gone.
What happened: An engineer ran git rebase origin/main on feature/NL-2047-kafka-dlq after a second engineer had checked out the branch and made commits locally. The rebase rewrote the SHAs of existing commits. The second engineer's local branch now diverges from the remote.
Recovery:
# Second engineer's recovery (their local commits are still in the reflog)
git reflog # find the last good commit SHA
git checkout -b feature/NL-2047-rescue <sha> # create a rescue branch
git log feature/NL-2047-rescue --oneline # verify commits are present
# Cherry-pick their commits onto the rebased branch
git checkout feature/NL-2047-kafka-dlq
git cherry-pick <sha-of-their-commit>Prevention:
- Never rebase a branch that more than one engineer is actively using.
- If rebase is needed after the branch is shared, communicate explicitly, agree a cutover point, and have all collaborators stash or commit their local work.
- Use squash merge instead of rebase for shared branch integration.
Diagnosis: git log --oneline --graph origin/feature/NL-2047-kafka-dlq shows the SHAs differ from the local branch — a clear indicator of a force-push/rebase event.
Guided Practice
Task: Simulate a conflict resolution and safe rollback in a local test repository.
Setup:
# Create a test repository
mkdir git-practice && cd git-practice
git init
git checkout -b main
echo 'kafka_broker = "kafka-broker.northline.internal:9092"' > config.txt
git add config.txt
git commit -m "chore: initial config"
# Create two branches that conflict
git checkout -b feature/engineer-a
echo 'kafka_broker = "kafka-broker-v2.northline.internal:9092"' > config.txt
git commit -am "fix(kafka): update to v2 broker address"
git checkout main
git checkout -b feature/engineer-b
echo 'kafka_broker = "kafka-broker.northline.internal:9094"' > config.txt
git commit -am "fix(kafka): update to port 9094"Exercise steps:
- Merge
feature/engineer-aintomain(no conflict). - Attempt to merge
feature/engineer-bintomain— a conflict will occur. - Resolve the conflict: the agreed value is
kafka-broker-v2.northline.internal:9094. - Complete the merge with a conventional commit message.
- Tag the result as
v0.1.0. - Simulate a bad deploy: create a
bad-changecommit that setskafka_broker = "wrong". - Use
git revertto undo it. - Verify
git log --onelineshows the revert commit and the original bad commit both in history.
Full solution:
# Step 1
git checkout main
git merge --no-ff feature/engineer-a -m "feat(kafka): update to v2 broker"
# Step 2
git merge feature/engineer-b # conflict
# Step 3 — edit config.txt to:
# kafka_broker = "kafka-broker-v2.northline.internal:9094"
# Remove conflict markers
# Step 4
git add config.txt
git commit -m "fix(kafka): resolve broker address to v2:9094 (merge NL-eng-a + NL-eng-b)"
# Step 5
git tag -a v0.1.0 -m "Release 0.1.0"
# Step 6
echo 'kafka_broker = "wrong"' > config.txt
git commit -am "bad change for practice"
# Step 7
git revert HEAD --no-edit
# Step 8
git log --oneline
# Should show: revert commit, bad commit, merge commit, engineer-a commit, initial commitIndependent Practice
Task: Write the branching strategy document described in the Deliverable. It must cover a fictional Northline service called northline-schema-registry — a shared library used by five downstream services, versioned with semver.
Acceptance criteria:
- Branch naming conventions defined (with examples for feature, fix, hotfix, release).
- Merge strategy chosen and justified for both (a) the daily feature workflow and (b) hotfixes.
- Branch protection rules listed (minimum 3 rules for
main, minimum 2 for release branches). - Tag format defined with a semver example.
- One pre-commit control described with its configuration mechanism.
- No invented compliance certifications or fabricated tool names.
Common Mistakes
- Force-pushing to a shared branch after a rebase. This rewrites history, breaks collaborators' local branches, and discards their work if they have local commits on the same branch.
- Using
git reset --hardto undo a merged commit onmain. Usegit revert. Reset on shared branches corrupts history for everyone. - Treating
.gitignoreas the only secrets control..gitignoreprevents staging files; it does not scan file contents. Pre-commit hooks with gitleaks or similar are required in addition. - Long-lived feature branches. Every day a branch diverges from
mainis a day of accumulated conflict. Merge within 1–3 days, use feature flags to hide incomplete work. - Vague commit messages.
fix stuffis useless forgit bisect, changelog generation, and code archaeology six months later. - Not specifying
-m 1when reverting a merge commit.git revert <merge-sha>without-m 1fails with a confusing error about multiple parents. - Assuming private repositories are safe for secrets. Repository access controls change. Private repositories have been made public accidentally. Any committed secret should be rotated immediately regardless of repository visibility.
Five Quick Checks
Q1. What is the difference between git revert and git reset --hard?
A1. git revert creates a new commit that undoes a previous commit — history is preserved and the action is auditable. git reset --hard moves the branch pointer backwards and discards commits from history — it rewrites history and is unsafe on shared branches.
Q2. A team uses squash merge for all feature branches. An engineer has 12 "wip" and "fix typo" commits on their branch. What happens to those commits when the PR is merged?
A2. All 12 commits are squashed into a single commit on main. The messy intermediate commits disappear from the shared history. Only the squash commit message (written by the engineer or reviewer at merge time) is preserved.
Q3. What is the purpose of CODEOWNERS?
A3. It automatically assigns specific teams or individuals as required reviewers for PRs that touch files or directories they own, ensuring domain experts review changes to sensitive areas.
Q4. An engineer finds a valid database password in a commit from three months ago. What is the first action?
A4. Immediately revoke and rotate the database password. The history rewriting and post-mortem can follow, but the credential must be treated as compromised from the moment it was first committed — regardless of when it was discovered.
Q5. Trunk-based development requires feature flags. Why?
A5. Because all changes go directly to main (and thus to production quickly), unfinished features must be hidden from users behind flags until they are complete. Without feature flags, partial or broken feature code would be visible to users as soon as it merges.
Quiz Alignment
| Objective | Quick Check | Practice task |
|---|---|---|
| Branch strategies | Q5 | Deliverable document |
| Merge strategies | Q2 | Worked Example A |
| Protected branches and CODEOWNERS | Q3 | Deliverable document |
| Commit hygiene | — | Worked Example A commit messages |
| Conflict resolution | — | Guided practice steps 2–4 |
| Rollback and revert | Q1 | Guided practice steps 6–8 |
| Secrets prevention | Q4 | Deliverable — pre-commit section |
Lesson Takeaways
- Trunk-based development and feature branches are not opposites — the key discipline is keeping branches short-lived.
- Squash merge gives clean linear history on
main; reserve rebase for pre-PR personal cleanup only, never on shared branches. - Protected branch rules (required reviews, required status checks, no force-push) are not bureaucracy — they are the mechanism that makes Continuous Delivery safe.
- Commit messages are the most-read documentation a team writes; Conventional Commits turns them into machine-readable release notes.
git revertis always the right tool on shared branches.git reset --hardis only safe on a local-only, never-shared branch.- Treat any committed secret as compromised immediately. Rotate first; investigate second.
Bridge to Next Lesson
In Lesson 4 — Continuous Integration & Quality Gates (#devops4), you will learn how the CI pipeline validates every change that flows through the branch protection rules introduced here: how triggers fire, how stages are structured, how lint and test jobs enforce code quality, how dependency and security scans catch vulnerabilities before they reach production, how artefact caching reduces build time, and how false-green pipelines are diagnosed and prevented. The protected branch status checks from this lesson become the enforced quality gates in the next.