Committing on purpose
By the end of this lesson you will have thrown one change away with a single command, kept your env files out of git with a .gitignore, and committed it with a sentence that says why — after reading git status and git diff first.
You know the four git commands. This is about using them deliberately once an assistant is writing most of the code.
Commit before you ask, not just after
A clean starting point is what makes a generated change reversible. If you have uncommitted work of your own mixed with a generated diff, undoing one means untangling both.
So: commit what works, then ask for the next thing. It costs ten seconds and it is what turns "this broke everything" into git restore ..
One change, one commit, one sentence
git commit -m "check res.ok before parsing, so a 429 stops showing blank rows"
What changed, and why. The why is the part you cannot reconstruct later, and it is the part an assistant cannot write for you — it does not know why you wanted it.
What must never be committed
Secrets. An API key committed once is in the history forever, and deleting it in the next commit does not remove it — anyone who cloned the repository still has it.
This is why .gitignore exists and why Build Your First Tool spends a whole lesson on the key. The rule to carry from here: before every commit, look at what you are about to add. git status and git diff take five seconds.
Undoing, three ways
git restore . throw away uncommitted changes (the same as in lesson 16)
git reset --soft HEAD~1 undo the last commit, keep the work
git revert <commit> add a commit that undoes an old one
The first is the one you will use constantly, and knowing it exists changes how you work: an experiment you can throw away in one command is an experiment worth running.
Try it now
First bring back the fake key file you deleted in lesson 17: create .env.local in your course folder holding the one line EODHD_API_KEY=not-a-real-key. It is what this lesson keeps out of git, and git status now lists it as untracked.
Make a change you do not want, then throw it away with git restore .. Then make one you do want and commit it with a real sentence. Feeling how cheap the undo is changes how willing you are to try things, which is most of what makes people improve quickly.
Let the change you want be a file called .gitignore holding one line, .env*, so that no env file can ever be staged by accident.
The prompt
Before you commit, hand the look to your agent, and keep the commit for yourself:
I am about to commit. Run git status and git diff and show me both
outputs in full. Then, file by file, tell me whether anything listed
looks like a key, a password, or a file the machine can regenerate.
Do not stage, commit or change anything. I will write the message.
A good answer shows both outputs unedited, says .env.local must never be added, and stops there.
Check it yourself
- After
git restore .,git statuslists no modified files. Untracked files such as.env.localare left alone: the command only restores files git already records. - The agent ran
git statusandgit diffand nothing that changes files or the staging area: nogit add, nogit commit. - With
.gitignorein place,git statusno longer lists.env.localat all. - Your message says why as well as what, and
git log -1shows it. git show --stat HEADlists exactly the files you meant to commit.
Break it on purpose
Before you write the .gitignore, run git add . and then git status. .env.local is listed under changes to be committed — one git commit away from being in the history forever. Take it back out with git restore --staged .env.local, then write the .gitignore.
Compare with ours
Our .gitignore and commit
$ cat .gitignore
.env*
$ git status --short
?? .gitignore
$ git log -1 --format=%s
Ignore .env files, so git add . can never stage a key
.env.local is still on disk and no longer in the list: ignored, which is what you want for every file that will ever hold a key.
Checkpoint
git status # only the files you expect, and no .env*
git add -A
git commit -m "Ignore .env files, so git add . can never stage a key"
Then answer this lesson's questions.