Chapter 26Lesson 03~180 minutes

Production Capstone: Design, Secure, Scale, and Recover a Governed Git Workflow: Security, Governance, and Reliability Validation

Validate the operating policy for developer/automation configuration, refs and history rewrite, credentials/signing/trust, safe directories, secret incidents, maintenance/retention, scale choices, dependencies, backup/migration, and hosted enforcement boundaries.

Security policyGovernanceReliabilityPlatform boundaries

Learning objectives

  • Document small, inspectable developer and automation Git baselines.
  • Define branch/release/merge/rebase/force-update policy with least privilege.
  • Define credential, signing, safe.directory, secret-response, and integrity controls.
  • Choose maintenance, retention, large-repository, and dependency policies from operational needs.
  • Separate core Git controls from server/hosting-platform enforcement.

1. Governance begins with effective configuration evidence

git config --list --show-origin --show-scope
git config --show-origin --get user.name
git config --show-origin --get user.email
git config --show-origin --get pull.rebase
git config --show-origin --get merge.ff
git config --show-origin --get-all credential.helper
git config --show-origin --get-all safe.directory
git config --show-origin --get gpg.format
git config --show-origin --get commit.gpgSign
git config --show-origin --get tag.gpgSign

System, global, local, worktree, environment, and command-line configuration can all affect behavior. Policy should describe intended effective behavior, not assume a single file is authoritative.

2. Developer baseline

Set explicit author identity, but keep authentication outside commit metadata. Developers may configure editors/pagers/aliases for convenience; shared policy should focus on settings that affect integration, trust, safety, or automation.

git config --global user.name "Learner Example"
git config --global user.email "learner@example.invalid"

3. Automation baseline

Read-only CI should not inherit a personal profile or signing key. A write-capable bot should use repository-local metadata identity plus isolated credentials. Noninteractive jobs must declare exact checkout/fetch requirements and must not depend on an editor prompt.

4. Branch and ref ownership policy

Ref Owner Allowed change Rewrite policy
trunk integrators reviewed integration no routine rewrite
topic/* contributors proposal work rewrite only before shared review by policy
release-state release automation/operators monotonic release metadata normal fast-forward only
refs/tags/v* release role approved release names published names immutable

5. Merge/rebase policy

Rebase is appropriate for private unpublished topics because only the author consumes those commit IDs. Shared integration/release refs should be stable. Document whether integration uses merge commits, fast-forward, squash, or another convention; do not let automation silently choose per run.

6. Force-update policy

Default policy is no force update. If an approved rewrite is unavoidable, current Git's most explicit lease form records the exact expected remote value:

git push --force-with-lease=refs/heads/topic/example:EXPECTED_OID \
  origin HEAD:refs/heads/topic/example
History replacement: use only in a disposable/approved workflow after backup, recipient coordination, exact expected-OID capture, and verification. Blind --force is prohibited.

7. Credential and least-privilege policy

Build runner: read-only repository access. Release bot: write only the owned release-state ref. Deployment reconciler: source read plus separate target-system permission. Use secure OS/platform helpers or short-lived credentials; never embed tokens in repository URLs or logs.

8. Signing and trust policy

Document whether commits, release tags, or both require signatures; allowed format (OpenPGP, X.509, SSH); trusted signer mapping; key rotation/revocation; and where verification occurs. commit.gpgSign and tag.gpgSign can enable defaults, but they do not provision trust or authorization.

9. safe.directory ownership policy

Git's ownership protection should remain enabled. Fix runner/container ownership where possible; otherwise add only the exact intentionally shared workspace in protected configuration. Wildcard safe.directory=* is not the standard workaround.

10. Secret policy: prevention → rotation → remediation

Prevent secrets through secret managers, synthetic examples, local/CI scanning, and review. If a real credential is committed, revoke/rotate it first. Preserve evidence and inventory refs/copies, then rewrite affected history using a current tool such as git filter-repo in a fresh disposable remediation clone. Git's own filter-branch manual recommends alternatives because of safety/performance pitfalls.

11. Integrity and transfer checks

git fsck --full
git commit-graph verify
git multi-pack-index verify

Run auxiliary checks only when the structures exist. A clean fsck is not malware scanning, signature verification, or authorization policy.

12. Maintenance and retention policy

Current maintenance supports scheduled/incremental work. Prefer measured background tasks for long-lived repositories. During active recovery/forensics, hold destructive expiry/pruning so recovery evidence remains available.

13. Large-repository policy

Measured problem Mechanism Constraint
working-tree scanning FSMonitor/untracked cache/sparse checkout platform/filesystem support
history traversal commit-graph/Bloom filters auxiliary write/compatibility
many packs MIDX/incremental repack I/O/maintenance windows
clone/fetch volume partial/shallow clone server support/graph needs
large binary objects Git LFS external store and migration

14. Dependency policy

Submodules are separate repositories. LFS stores large content outside ordinary Git objects. Server-side hooks, branch rules, hosted issues/PRs/releases/packages, CI variables, and deployment state are also external. Every one needs an owner in backup/migration/restore plans.

15. Backup, restore, and migration policy

Periodically create a verified full bundle for the governed refs and restore it into a separate repository. Compare exact ref names/OIDs and run fsck. A mirror can complement the bundle, but neither reproduces hosted metadata or external stores automatically.

16. Server/hosting enforcement boundary

The local capstone cannot enforce protected branches, required reviews/checks, merge queues, environment approvals, organization permissions, hosted scanning, or CI token scopes. Implement those later in GitHub/GitLab/server-specific policy while retaining the portable Git-level invariants taught here.

17. Worked decision table

Decision Choice Reason Cost
integration stable trunk auditability coordination before merge
release bot dedicated monotonic branch normal push protects races extra ref governance
CI detached exact OID; shallow only when sufficient reproducible provenance extra fetch when history/tags required
backup verified full bundle + restore drill offline proof storage/testing
secret leak rotate then coordinated rewrite secrecy first history replacement and downstream cleanup

18. Knowledge check

Why doesn't user.email determine server permissions?

When is explicit force-with-lease appropriate?

Why rotate before history cleanup?

Which feature accelerates ancestry/history traversal?

Which controls remain server responsibilities?

19. Summary

The governed design now covers configuration, branch/rewrite rules, credentials/signing/trust, secret response, ownership trust, integrity, maintenance/scale, dependencies, backup/restore, and platform enforcement.

Next

Break the system deliberately

Lesson 4 injects concurrency, conflict, lost-ref, release-tag, shallow-CI, fake-secret, corruption, performance, target-selection, and restore-dependency failures.

Authoritative references

 git-config
 git-push
 history-filtering warning
 git-maintenance
 git-fsck

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0 Send only Ethereum/ERC-20 compatible assets to this address.