Versioning home lab config with Git: Compose files in, secrets out
Yes, a home lab's configuration belongs in Git, and no, a folder of
backup copies named compose-final-v2.yaml is not the same
thing. A backup answers "is there another copy?" Git answers the
questions a fault actually asks: what changed, when, and why, and it
makes the previous working state one command away instead of a
reconstruction project. The myth worth retiring first is that this
needs Kubernetes, a CI pipeline, or any automation at all. The manual
habit is the whole foundation: edit in the repository, never on the
host.
What goes in, what never goes in
| In the repo | Never in the repo |
|---|---|
| Compose files, one folder per service | Real .env files holding passwords, tokens, and keys |
| Application config files the services mount | Private keys and certificates' private halves |
.env.example, variable names with placeholder values | Databases, media libraries, and other service data |
| Setup and maintenance scripts | Backup archives (they belong in the backup system, not the config history) |
| A short README per service: what it is, where its data lives | Anything the lab would have to rotate if the repo leaked |
The secret boundary is structural, not careful. Secrets live in an
.env file beside the Compose file that uses it, the
Compose file references variables instead of values, and
.env is listed in .gitignore from the very
first commit. The committed .env.example carries the same
variable names with placeholder values, so a rebuild knows what to
fill in without the repo ever holding a real credential. A private
remote is still the right default, the repo describes the lab's
layout in useful detail, but the design goal is stronger: if the
repo did leak, nothing in it would work as a key.
The gitignore trap, straight from the Git docs
One sentence in Git's official gitignore documentation
causes more accidental secret leaks than any missing rule: files
already tracked by Git are not affected by ignore patterns. A
gitignore file specifies intentionally untracked files to
ignore, it governs what Git picks up next, not what it already holds.
So an .env committed on day one, before the ignore rule
existed, keeps being tracked and keeps being pushed, rule or no rule.
The documented fix to stop tracking a currently tracked file is
git rm --cached <file>, which removes it from the
index while leaving it on disk, followed by a commit.
Be clear about what that fix does not do. It stops future exposure; it does not un-publish history. A credential that reached a pushed commit should be treated as compromised and rotated, changed at the service that issued it, because deleting the file from later commits leaves the value sitting in earlier ones. Prevention is one line in the first commit. The cure is a rotation plus a history decision, and it is never as cheap.
The Git-first change procedure
- Clone the repo to the machine used for editing, a workstation, not the server. The server is where configuration is deployed, not where it is created. One folder per service under the repo root keeps each Compose project self-contained.
- Make the change in the repo. Edit the Compose file or config on the workstation. Keep each commit to one logical change: an image version bump is one commit, a port change is another.
- Read the diff before committing.
git diffshows exactly what is about to become history. Anything unexpected in that output, a stray value, a pasted secret, stops the commit here, where stopping is free. - Commit with the reason, then push. A message like "Update app container from 2.3.1 to 2.4.0" turns history into documentation: the change and its context travel together. Push to the private remote.
- Deploy from the repo on the host. On the Docker
host,
git pullin its clone of the same repo, thendocker compose up -din the changed service's folder. The host now runs exactly what the repo describes. - Verify the service is healthy, it answers on its port, its logs show a clean start, and the household-facing function works. Only then is the change done.
What success looks like: git status on
the host's clone reports a clean tree that matches the remote, the
changed service is running the committed configuration, and
git log explains the last change in one line a stranger
could follow.
Rollback is a revert, not a reconstruction
When a change breaks something, the previous working configuration
is already stored, that is the point of the whole setup. Run
git diff HEAD~1 to confirm exactly what the suspect commit
changed, then git revert it (or check out the Compose
file from the previous commit for a quick test), pull on the host,
and redeploy. Minutes, and the lab is back on a state that is known
to have worked, with the failed attempt still recorded in history
where it can be studied instead of repeated. Compare the alternative
this replaces: editing files directly on the host over SSH, where six
months of small changes leave no record of why a setting exists, when
it changed, or whether the file on the server matches any other copy.
Small questions, straight answers
Does the repo replace backups? No. Git versions the instructions for rebuilding the lab; backups protect the data the services hold. A restore needs both: the repo recreates the service, the backup repopulates it.
Self-host the Git remote? It is a legitimate option, a lightweight self-hosted Git service is one more container, but it makes the recovery tool depend on the lab it is meant to recover. An off-lab private remote keeps the repo reachable when the lab itself is the thing being rebuilt.
One repo or one per service? One repo. The lab is one system; a single history shows cross-service changes, a network rename touching four Compose files, as the single event they were.
When Git is not enough
Git versions files. It does not version the state inside a database, the firmware on a switch, or settings that live only in a web admin panel. Export what those systems allow exported, commit the exports alongside the service they belong to, and note the gaps honestly in the service README. Automation, tools that watch the repo and deploy on their own, is a layer that can be added later, and the sources for this workflow agree on the order: get the manual pattern normal first. A lab whose owner commits every change, with secrets structurally excluded and rollback rehearsed, has the part of GitOps that pays. The rest is scheduling.
, Dex Carter, Tech Writer