How an Agent Commits
Identity, messages, staging, and what must never enter history.
Learning objectives
- Turn a reviewed diff into one commit with an honest message
- Set an author identity so agent commits are distinguishable
- Keep secrets, build output, and huge generated junk out of history
Commit is the moment of responsibility
Editing changes the working tree. Committing says this snapshot is part of the history. That is the line an agent should not cross alone until you have seen the diff, or until a pull request will force a second look before main moves. Many teams let the agent commit on a branch and reserve the merge for a person. That is the pattern this book recommends.
# See what will be included. Unstage anything that does not belong.
git status
git add app/reserve.php views/class.php
git diff --cached # the exact snapshot you are about to keep
git commit -m "Add a waitlist when a class has no seats left"
git diff --cached is the staged diff. If you skip it, you are trusting git add ., and git add . will happily include a .env the agent created beside the real fix.
Who is the author?
Git records user.name and user.email on every commit. If the agent uses your name, the history claims you typed the lines. If every commit says bot, you cannot tell which tool did it. Use an identity that is true.
# On the machine where the agent runs. This does not change old commits.
git config user.name "Workshop Co. Agent"
git config user.email "agent@workshopco.ca"
Your own commits, made from your editor without the agent, can use your name. The point is not bureaucracy. The point is that git log answers “human or agent?” without opening a chat transcript. Some tools set this automatically. Check it with git log -1 --format='%an %ae' after the first agent commit.
What a message has to say
The message is the index of the audit log. “update” and “fix stuff” make the history useless. A usable message names the behavior, not the vibe:
- Good: “Add a waitlist when a class has no seats left.”
- Weak: “Improve booking.”
- Dishonest: “Fix seats” when the diff also upgrades a framework.
One purpose per commit. If the agent mixed a waitlist with a redesign, ask it to split the work, or unstage the redesign and commit it separately later. Future you will revert the waitlist without reverting the redesign only if they are not glued together.
What must never be committed
History is forever in practice. Deleting a file in a later commit does not remove it from older commits. Anyone with the repository can check out last Tuesday. So these stay out:
- Passwords, API keys, database URLs, private SSH keys,
.envwith real values node_modules, build folders, and SQLite files that contain customer bookings- A dump of the production database “so the agent can see real data”
Put patterns in .gitignore before the agent’s first commit, not after. A reasonable start for the booking app:
.env
.env.*
!.env.example
node_modules/
studio.db
*.sqlite
Rotating the password matters more than rewriting Git history. Assume the secret is copied. Change it on the host, in the database, and at the API vendor. Then remove it from the current files. Rewriting old commits with force-push is a specialist task, and it destroys the audit trail for everyone who already pulled.
Write the commit
The staged diff adds a waitlist and also changes DATABASE_URL inside .env. Write the command you refuse to run, and the commands you run instead.
Answer
Refuse git add . followed by a commit. Run git restore --staged .env if it was staged, confirm .env is gitignored, git add only the waitlist files, git diff --cached, then git commit -m "Add a waitlist when a class has no seats left". Rotate the database password if the URL was ever pushed or pasted into a chat you do not control.