T7 Git and GitHub · Lesson 7
Good habits
A repository is read far more often than it is written. Give every commit a title that says what it does and a body that says why, keep each commit to one change, and name your releases with tags. Undo published work with git revert and your own with git reset, set unfinished work aside with git stash, and never let a secret into the history.
- write a commit message that says what changed and why
- keep each commit to one change, so it can be read, found and undone alone
- name the commits that matter with tags, and push them
- undo a change with git revert, and your own unpushed commits with git reset
- set unfinished work aside with git stash, and bring it back
- keep secrets out of a repository, and know what to do when one gets in
The back cover
A repository is read far more often than it is written. Months later, you or someone else will ask why a line changed, and the history is the only place that can answer.
These pages show commit messages that explain, and commits that each hold one change. They show tags, the names that mark releases, and the safe ways to undo a commit. They also show how to set unfinished work aside, and why secrets must never go into a repository at all. Each habit is small on its own.
Before you start
The story: The drawer that does not say why
A year ago someone changed the orders so that gate 6 never opens on Sundays. Now gate 6 is needed on Sundays, and nobody dares to change it back. The picture in the drawer says only: fix.
Nobody knows what was fixed, or why, or what changing it back might break.
Keeper Hollis reads the one word aloud and sighs. "This is why I ask for the why," she says. "A drawer is only as good as the notes in it."
Lessons 01 to 06 taught what git can do. This last lesson is about doing it well: habits that keep a repository easy to read, safe to change and safe to share, months and years later, for people who were not there when the work was done.
It builds on these ideas. Each one has a tiny example, so you can check that you remember it.
| What you already know | A tiny example | Where it comes back |
|---|---|---|
| A commit and its message. | git commit -m 'First orders' | Messages that say why. |
| The history. | git log --oneline | Reading what a message tells you. |
| One commit's change. | git show HEAD | What a change did, line by line. |
| The tray. | git add orders.txt | Choosing what goes into each commit. |
| Undoing on the desk. | git restore orders.txt | Undoing a commit is a bigger step. |
| Ignoring files. | .gitignore | Keeping secrets out. |
| Relative names. | HEAD~1 | Naming the commit to undo. |
| Rewriting your own commit. | git commit --amend | Fine before a push, not after. |
| Pushing. | git push -u origin main | Tags are pushed by name. |
| A detached HEAD. | git switch --detach | Looking at a tagged version. |
By the end of this lesson you will be able to:
- write a commit message that says what changed and why;
- keep each commit to one change, so it can be read, found and undone alone;
- name the commits that matter with tags, and push them;
- undo a change with git revert, and your own unpushed commits with git reset;
- set unfinished work aside with git stash, and bring it back;
- keep secrets out of a repository, and know what to do when one gets in.
How to follow this lesson
Every block starts in the shop's repository, in the state that its label describes. Run each one, change it, and run it again: nothing you do here can harm a real repository.
In one line
This lesson is about good habits: clear messages, small commits, tags, safe undoing, the stash, and keeping secrets out.
Commit messages that explain
At a glance
A commit message is a note to a future reader, often yourself, who wants to know why a line changed.
It has a short title of at most 50 characters that says what the commit does, written as an order, such as Close gate 2 for repairs. Then comes a blank line, and a body that says why the change was made. Both can be written on the command line with two -m options: the first becomes the title, the second the body.
Take a guess: Can one commit name more than one author?
Here is the drawer from the story. Someone closed gate 6 on Sundays a year ago. Read the history:
In the same repository, where the pump checks were added after that fix
git log --oneline
e2ac712 (HEAD -> main) Add the pump checks
2afab73 fix
aba517b First orders
The middle commit says only fix. Fix what? git show tells you what changed, line by line:
In the same repository, where the pump checks were added after that fix
git show HEAD~1
commit 2afab73d9c42239f3d6d622acf567f2d6cb8b560
Author: Asha <asha@tower.example>
Date: Thu Jan 1 10:00:04 2026 +0000
fix
diff --git a/orders.txt b/orders.txt
index 060e3cf..c2180ec 100644
--- a/orders.txt
+++ b/orders.txt
@@ -1,3 +1,4 @@
open gate 4 at noon
close gate 2
check gate 5
+close gate 6 on Sundays
The change is one line, close gate 6 on Sundays. But nothing says why. Was it a fault in the gate? A rule of the city? A complaint? The diff cannot say, and the person who knew has moved on. So nobody dares to undo it. This is the cost of a poor message: the code survives, and the reason dies.
What a good message holds
Git's own manual gives the shape. A commit message starts with one short line, of at most 50 characters, that says what the commit does. That line is the commit's title, or subject, and git shows it everywhere: in git log --oneline, in git show, and on GitHub. Then comes a blank line. Then comes the body: as many lines as you need, saying why the change was made, and anything a reader will need to know later.
You can write both parts with -m. Each -m makes one paragraph, and git puts a blank line between them:
In the shop's repository, with one commit, First orders
echo 'close gate 6 on Sundays' >> orders.txt
git commit -q -am 'Close gate 6 on Sundays' -m 'The Sunday market fills the lane by gate 6, so carts cannot pass.'
git log -1
commit 59357dc4e5dfba6d3aa61470b15b72d19016c968 (HEAD -> main)
Author: Asha <asha@tower.example>
Date: Thu Jan 1 10:00:04 2026 +0000
Close gate 6 on Sundays
The Sunday market fills the lane by gate 6, so carts cannot pass.
Now the reason travels with the change, for as long as the repository lives. In the short view, you still see only the title, so the history stays easy to scan:
In a repository with the same history, written with a full message
git log --oneline
d3e4cef (HEAD -> main) Add the pump checks
59357dc Close gate 6 on Sundays
aba517b First orders
A reason in words can also be searched. git log --grep lists the commits whose message contains a pattern. The new clerk in the story searches for market and finds the reason at once:
In a repository with the same history, written with a full message
git log --oneline --grep=market
59357dc Close gate 6 on Sundays
--grep reads the whole message, body included, and it minds capital letters: --grep=sunday finds nothing here, as the message says Sunday. Add -i to ignore case.
| A poor title | A good title | Why it is better |
|---|---|---|
| fix | Close gate 6 on Sundays | says what the commit does |
| changes | Open gate 4 at one, not noon | names the one change |
| stuff for Corin | Add the pump checks | describes the work, not the person |
| Fixed the bug. | Stop gate 2 closing twice | says which bug, as an order, with no full stop |
Git's own project asks its contributors to write the title in the imperative mood, as if giving orders to the code: Close gate 6, Add the pump checks, not Closed gate 6 or Adds the pump checks. It also asks you to leave off the full stop, and says that the goal of the message is to convey the why behind the change. Put the reasons, the numbers and the warnings in the body.
Fixing a message before you push
If the poor message is on your last commit, and you have not pushed it, lesson 06's --amend rewrites it:
In the shop's repository, where someone added close gate 6 on Sundays to the orders, with the message fix
git commit -q --amend -m 'Close gate 6 on Sundays' -m 'The Sunday market fills the lane by gate 6, so carts cannot pass.'
git log --oneline
50ccba9 (HEAD -> main) Close gate 6 on Sundays
aba517b First orders
The commit gets a new name, 50ccba9, because its message is part of what is hashed. After a push, others may already have the old commit, so you do not rewrite it. You explain in the next commit instead, or in the pull request's description.
Worked example 1
Gate 4 must now open at one, not at noon, because the noon bell has moved to the clock tower. Make the change and commit it with a message that a stranger could understand in a year.
What we have: orders.txt with open gate 4 at noon
What we need: one commit whose title says what changed and whose body says why
The plan: change the line with sed; commit with two -m options: a short title, then the reason; read it back with git log -1
In the shop's repository, with one commit, First orders
sed -i 's/at noon/at one/' orders.txt
git commit -q -am 'Open gate 4 at one, not noon' -m 'The noon bell has moved to the clock tower, and the carts now arrive at one.'
git log -1
commit f6768ddec9c5ee74babf5fe66a2168ac56862eb4 (HEAD -> main)
Author: Asha <asha@tower.example>
Date: Thu Jan 1 10:00:04 2026 +0000
Open gate 4 at one, not noon
The noon bell has moved to the clock tower, and the carts now arrive at one.
- The title has 28 characters, well under 50, and says what changed. The body gives the reason, which the diff alone could never show.
One commit, titled Open gate 4 at one, not noon, with its reason in the body.
Check: git log --oneline shows only the title, and git log --grep=bell finds the commit.
A path that fails: one long -m with the title and the reason together. The title would then run past 50 characters, and every short view of the history would cut it off or wrap it.
When you are stuck: you do not know what to write in a message
Finish the sentence "This commit will..." in under 50 characters: that is the title.
Then ask what a stranger would need to know a year from now: why this change, why now, what it affects. That is the body.
If the title needs the word and, the commit probably holds two changes: see the next section.
Your turn
git log --oneline -1 HEAD~1
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
59357dc Close gate 6 on Sundays
- HEAD~1 is the commit before the pump checks.
- --oneline shows the short name and the title, not the body.
It prints 59357dc Close gate 6 on Sundays.
Which part of a message does git log --oneline show?Tap to reveal
- It shows one line for each commit.
The title: the text up to the first blank line.
Rewrite the title fixed stuff for a commit that stops gate 2 closing twice.Tap to reveal
- Say what the commit does, as a command.
- Keep it under 50 characters.
Stop gate 2 closing twice.
Did you know?
More than one author
A commit has one author, but its message can credit more. GitHub's documentation says to add one or more Co-authored-by trailers, lines at the end of the message, to attribute a commit to several authors. Each line names one co-author with a name and the email address that person uses. GitHub then attributes the commit to all of them.
Why it fits here: It answers this topic's question: Co-authored-by lines at the end of a message credit more than one author.
Source: GitHub Docs: Creating a commit with multiple authors
A type in front of the title
Some projects give every title a type. The Conventional Commits specification asks for messages shaped as a type, an optional scope in brackets, a colon and a description. A fix patches a bug, and a feat adds a new feature. The specification lists its reasons: tools can then generate change logs and work out the next version number from the types of the commits.
Why it fits here: It shows a stricter form of this topic's titles: Conventional Commits puts fix: or feat: in front, so tools can read the history.
Source: Conventional Commits 1.0.0
In one line
A commit message is a short title of at most 50 characters that says what the commit does, a blank line, and a body that says why. Write both with two -m options.
Small commits, one change each
At a glance
A commit that holds one change is easy to read, easy to review and easy to undo. A commit that holds three changes is none of those.
Keep each commit to one change. Put only that change's files on the tray, check what will be filed with git diff --staged, and then commit. If the title needs the word and, as in Fix the pump and rename the log, that is usually a sign of two changes that belong in two commits.
Take a guess: How can small commits help you find the commit that brought in a bug?
A commit is easiest to read, to review and to undo when it holds one change: one fix, one new rule, one feature. Suppose that two unrelated pieces of work are on your desk at the same time. Gate 7 is to open, and pump 8 is to be checked:
In the same repository, where the pump checks were added after that fix
echo 'open gate 7' >> orders.txt
echo 'check pump 8' >> pumps.txt
git status -s
M orders.txt
M pumps.txt
git commit -am would put both into one commit, with a title such as Open gate 7 and check pump 8. That and in the title is a warning sign. Instead, put one change on the tray, commit it, then the other:
In the same repository, where the pump checks were added after that fix
echo 'open gate 7' >> orders.txt
echo 'check pump 8' >> pumps.txt
git add orders.txt
git commit -q -m 'Open gate 7'
git add pumps.txt
git commit -q -m 'Check pump 8 as well'
git log --oneline --stat -2
fbd5074 (HEAD -> main) Check pump 8 as well
pumps.txt | 1 +
1 file changed, 1 insertion(+)
2c9b0cc Open gate 7
orders.txt | 1 +
1 file changed, 1 insertion(+)
--stat shows, under each commit, the files it changed. Each commit touches one file and does one thing, and each title needs no and.
Why small commits pay
| With one change in each commit | you can |
|---|---|
| a short, true title | read the history at a glance |
| a small diff | review it in a minute, in a pull request |
| nothing else mixed in | undo it alone with git revert, later in this lesson |
| a clear place in the history | find when a line changed, and why |
The last row is worth seeing. With a file name after --, git log shows only the commits that changed that file. Here is the history of the orders:
In the same repository, where the pump checks were added after that fix
git log --oneline -- orders.txt
2afab73 fix
aba517b First orders
The pump checks are not listed, as they never touched orders.txt. In a large repository with thousands of commits, this is how you find the few that matter for one file. It only helps if each commit's title says what it did, which brings back the last section.
Check the tray before each commit
Before you commit, look at what is on the tray, so that nothing unrelated slips in. git diff --staged, from lesson 02, shows it; with --stat it lists only the files:
In the same repository, where the pump checks were added after that fix
echo 'open gate 7' >> orders.txt
echo 'check pump 8' >> pumps.txt
git add orders.txt
git diff --staged --stat
orders.txt | 1 +
1 file changed, 1 insertion(+)
Only orders.txt is on the tray, so the next commit will hold only the gate 7 change. When two changes sit in the same file, git add -p lets you choose, piece by piece, which parts of the file go on the tray. It asks a question for each piece, so it needs a person at the keyboard; try it in a real terminal.
How small is small?
Small means one idea, not one line. A new feature may take five commits, each a step that works on its own: add the file, use it in one place, then in another. A one-line fix is one commit. What matters is that each title tells the truth about the whole commit.
Worked example 2
Two jobs are done at once: gate 7 now opens, and pump 8 is to be checked. Commit them so that either one could later be undone alone, and show that each commit holds one file.
What we have: two changed files on the desk, orders.txt and pumps.txt
What we need: two commits, one for each change
The plan: put orders.txt on the tray and commit it; then pumps.txt; then git log --oneline --stat
In the same repository, where the pump checks were added after that fix
echo 'open gate 7' >> orders.txt
echo 'check pump 8' >> pumps.txt
git add orders.txt
git commit -q -m 'Open gate 7'
git add pumps.txt
git commit -q -m 'Check pump 8 as well'
git log --oneline -3
fbd5074 (HEAD -> main) Check pump 8 as well
2c9b0cc Open gate 7
e2ac712 Add the pump checks
- Two new commits, each with a title that needs no and. The stat in the earlier block showed one file under each.
Two commits: Open gate 7, and Check pump 8 as well.
Check: git log --oneline -- pumps.txt now lists Check pump 8 as well and Add the pump checks, and not Open gate 7.
A path that fails: git commit -am 'Open gate 7 and check pump 8'. It works, but if the gate 7 change must later be undone, the pump 8 change goes with it.
When you are stuck: one commit seems to hold two changes
Read its title aloud. An and in it usually means two changes.
Before committing, put one file on the tray with git add and a file name, and check with git diff --staged --stat.
For two changes in one file, use git add -p in a real terminal, which asks about each piece.
Your turn
git log --oneline -- pumps.txt
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
d3e4cef (HEAD -> main) Add the pump checks
- Only the commits that changed pumps.txt are listed.
- Close gate 6 on Sundays changed only orders.txt.
It prints d3e4cef (HEAD -> main) Add the pump checks.
A commit is titled Open gate 7 and fix the pump typo. What would be better?Tap to reveal
- The and joins two changes.
Two commits: Open gate 7, and Fix the pump typo.
Which command shows the files on the tray, before you commit?Tap to reveal
- It is the diff of the tray, from lesson 02, made short.
git diff --staged --stat.
Did you know?
bisect finds the guilty commit
Small commits pay off when a bug appears. The git bisect manual says it uses a binary search to find which commit in a project's history introduced a bug. You mark one commit bad and an older one good, and git checks out commits between them for you to test. Its own example has 675 commits left to test, roughly 10 steps. A small commit then points at the exact change.
Why it fits here: It answers this topic's question: git bisect finds the commit that brought in a bug, and a small commit pins it down.
Source: git manual: git-bisect
The diff below the message
Writing the message is easier with the change in view. The git commit manual says -v, for verbose, shows the diff between the last commit and what would be committed at the bottom of the message template, to remind you what the commit holds. The diff is not saved into the message. A diff too long to describe in one title is a sign the commit holds too much.
Why it fits here: It adds a check to this topic's one change: git commit -v shows the whole diff while you write the title.
Source: git manual: git-commit
In one line
Keep each commit to one change: put only its files on the tray, check with git diff --staged, and commit. A title that needs the word and is a sign of two changes.
Naming the commits that matter: tags
At a glance
Some commits matter more than others: the one that became version 1.0, or the one that went live on a certain day. A tag gives such a commit a name that never moves.
Make a release tag as an annotated tag, git tag -a v1.0 -m with a message, which records who made it and when. List tags with git tag -n. A plain git push sends no tags, so push each one by name, as in git push origin v1.0.
Take a guess: What does GitHub build its Releases from?
Some commits matter more than others: the orders sent out for spring, the version of a program that was released. A tag gives such a commit a name that never moves. A branch moves forward with every commit; a tag stays where you put it.
In the same repository, where the pump checks were added after that fix
git tag v1.0
git tag
git log --oneline -1
v1.0
e2ac712 (HEAD -> main, tag: v1.0) Add the pump checks
git tag with a name tags the current commit. git tag alone lists the tags, and git log marks the tagged commit with tag: v1.0. A version number with a v in front, such as v1.0 or v2.3, is the most common way to name a release.
Annotated tags: a tag with a message
The tag above is a lightweight tag: only a name for a commit, like a branch that never moves. An annotated tag, made with -a and -m, is an object of its own in the repository. It holds who made the tag, when, and a message. Git's manual says that annotated tags are meant for releases, and lightweight tags for private or temporary labels.
In the same repository, where the pump checks were added after that fix
git tag -a v1.0 -m 'The spring orders'
git cat-file -t v1.0
git show -s v1.0
tag
tag v1.0
Tagger: Asha <asha@tower.example>
Date: Thu Jan 1 10:00:07 2026 +0000
The spring orders
commit e2ac712412a2371f1168fa69e0dc957513b7c958 (HEAD -> main, tag: v1.0)
Author: Asha <asha@tower.example>
Date: Thu Jan 1 10:00:06 2026 +0000
Add the pump checks
git cat-file -t, from lesson 01, says that v1.0 now names an object of type tag. git show prints the tag first, with its Tagger, Date and message, and then the commit it names (-s leaves out the diff). Wherever git needs a commit, such as in git log v1.0 or git switch --detach v1.0, it follows the tag to that commit.
You can tag an older commit by naming it, and git tag -n lists each tag with the first line of its message:
In the same repository as before, with the annotated tag v1.0 on its last commit
git tag -a v0.9 -m 'The winter orders' HEAD~1
git tag -n
v0.9 The winter orders
v1.0 The spring orders
Tags are pushed by name
A plain git push sends branches, not tags. This surprises many people:
In the same repository, whose main is pushed to origin, the bare repository ../hill.git
git tag -a v1.0 -m 'The spring orders'
git push 2>&1 | cat
git -C ../hill.git tag | wc -l
Everything up-to-date
0
main was already on the hill, so there was nothing to send, and the hill has no tags at all. Push a tag by its name, like a branch:
In the same repository, whose main is pushed to origin, the bare repository ../hill.git
git tag -a v1.0 -m 'The spring orders'
git push origin v1.0 2>&1 | cat
git -C ../hill.git tag
To ../hill.git
* [new tag] v1.0 -> v1.0
v1.0
git push --tags sends every tag at once. On GitHub, a release is built on a pushed tag: GitHub's documentation says that releases are based on Git tags, which mark a specific point in the history. A release adds notes and files for people to download.
Looking at a tagged version, and removing a tag
To see the files exactly as they were at a tag, switch to it. As in lesson 03, this is a detached HEAD, and git status names the tag:
In the same repository as before, with the annotated tag v1.0 on its last commit
git switch -q --detach v1.0
git status | head -n 1
HEAD detached at v1.0
git switch main brings you back. A tag made by mistake is removed with -d. For an annotated tag, git names the tag object itself:
In the same repository as before, with the annotated tag v1.0 on its last commit
git tag -d v1.0
Deleted tag 'v1.0' (was fb83d16)
Remove a tag only before you push it. Others may have fetched a pushed tag and rely on it; a tag is a promise that this name means this commit, for good.
| Command | What it does |
|---|---|
git tag v1.0 | a lightweight tag on the current commit |
git tag -a v1.0 -m 'msg' | an annotated tag, with a tagger, a date and a message |
git tag -a v0.9 -m 'msg' HEAD~1 | a tag on an older commit |
git tag, git tag -n | the tags, and with -n their messages |
git push origin v1.0, git push --tags | one tag, or all of them, to the remote |
git tag -d v1.0 | removes a tag, here only |
Worked example 3
The spring orders are ready to send out. Mark the commit as release v1.0, with a message, and put the tag on the hill, so that every hall can find this version.
What we have: main pushed to the hill, with no tags
What we need: an annotated tag v1.0 on the last commit, on the hill as well
The plan: git tag -a with -m; then push the tag by name; check the hill's tags with git -C
In the same repository, whose main is pushed to origin, the bare repository ../hill.git
git tag -a v1.0 -m 'The spring orders'
git push -q origin v1.0
git -C ../hill.git tag -n
v1.0 The spring orders
- The hill has the tag with its message, so anyone who fetches gets it, and a clone has it from the start.
v1.0 marks the spring orders, here and on the hill.
Check: git -C ../hill.git cat-file -t v1.0 prints tag.
A path that fails: git push after tagging, and nothing else. It answers Everything up-to-date, and the tag stays only in your repository.
When you are stuck: a tag is missing on the remote
git push does not send tags. Push the tag by name: git push origin v1.0.
git -C on a bare repository, or git ls-remote origin, shows what the remote has.
A tag of the same name already on the remote is refused (already exists): tags are meant never to move.
Your turn
git cat-file -t v1.0
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
tag
- v1.0 was made with -a and -m.
- An annotated tag is an object of its own.
It prints tag.
What is the difference between a branch and a tag?Tap to reveal
- What happens to each when you commit?
A branch moves with each new commit; a tag stays on its commit.
You tagged v1.1 and ran git push. Is the tag on the remote?Tap to reveal
- What does a plain push send?
No: push it with git push origin v1.1.
Did you know?
Releases stand on tags
GitHub's Releases page is built on tags. Its documentation calls releases deployable software iterations that you can package and offer to a wider audience to download and use. It says releases are based on git tags, which mark a specific point in a repository's history. A tag's date may differ from the release's date, since the two can be made at different times.
Why it fits here: It answers this topic's question: every GitHub release stands on a git tag that marks the released commit.
Source: GitHub Docs: About releases
A name for every commit after a tag
A tag also gives later commits a readable name. The git describe manual says it finds the most recent tag reachable from a commit, then adds the number of commits on top of it and a short name of the latest commit. Its example, typed at Linus Torvalds's own prompt, prints v1.0.4-14-g2414721: 14 commits after v1.0.4, at commit 2414721.
Why it fits here: It shows a use of this topic's tags: git describe names any commit by its distance from the last tag.
Source: git manual: git-describe
In one line
A tag is a name for one commit that never moves. Make releases with annotated tags (git tag -a -m), list them with git tag -n, and push each one by name, as a plain push sends no tags.
Undoing a change: revert and reset
At a glance
Some commits turn out to be mistakes. How to undo one depends on one question: has it been pushed?
The command git revert undoes a commit by making a new commit with the opposite change. The history stays whole, so it is safe after a push; add -n to write your own message, then git commit. The command git reset moves your own branch back instead, for commits nobody else has. With --soft their changes stay on the tray, by default on the desk, and with --hard nothing is kept.
Take a guess: Why does git have three commands with names as alike as reset, restore and revert?
Gate 6 must open on Sundays again: the Sunday market has moved to the square. The change to undo is the commit called fix, which is no longer the last one. The pump checks came after it.
git revert: a new commit that undoes an old one
git revert makes a new commit that does the opposite of an old one. It does not remove the old commit; the history keeps both, the change and its undoing. --no-edit takes git's own message instead of asking for one in an editor:
In the same repository, where the pump checks were added after that fix
git revert --no-edit HEAD~1
git log --oneline
cat orders.txt
[main e8a5518] Revert "fix"
Date: Thu Jan 1 10:00:07 2026 +0000
1 file changed, 1 deletion(-)
e8a5518 (HEAD -> main) Revert "fix"
e2ac712 Add the pump checks
2afab73 fix
aba517b First orders
open gate 4 at noon
close gate 2
check gate 5
The line close gate 6 on Sundays is gone from the orders, and the pump checks are untouched. Git found the opposite of that one commit and applied it on top of everything since. The summary line Date gives the new commit's date, as git revert always does.
Because a revert only adds a commit, it is safe on work that others already have: nothing they hold is rewritten. That makes git revert the way to undo a commit that has been pushed. On GitHub, a merged pull request has a Revert button, which creates a new pull request that reverts the merge commit.
A revert with a message of your own
git's message, Revert "fix", repeats the poor title. To say why the change is undone, revert with -n (no commit), which applies the undoing to the tray and the desk and stops there:
In the same repository, where the pump checks were added after that fix
git revert -n HEAD~1
git status
On branch main
You are currently reverting commit 2afab73.
(all conflicts fixed: run "git revert --continue")
(use "git revert --skip" to skip this patch)
(use "git revert --abort" to cancel the revert operation)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: orders.txt
git status says that a revert is under way. Now commit it with a good message, and the revert is done:
In the same repository, where the pump checks were added after that fix
git revert -n HEAD~1
git commit -q -m 'Open gate 6 on Sundays again' -m 'The Sunday market has moved to the square, so the lane by gate 6 is clear.'
git log --oneline
0fc84b6 (HEAD -> main) Open gate 6 on Sundays again
e2ac712 Add the pump checks
2afab73 fix
aba517b First orders
In git revert, -m is not a message
In git commit, -m gives the message. In git revert, -m means something else: which parent to keep when the commit being reverted is a merge. It expects a number, so git revert -m 'Open gate 6 again' HEAD~1 is refused. Give a revert its message with -n and a commit, as above.
git reset: moving your own branch back
git reset moves the current branch back to an earlier commit, as if the later commits had not been made. It is the tool for your own commits that nobody else has yet: never use it on commits you have pushed, because it rewrites the history that others hold. It has three strengths, which differ in what happens to the work in the commits it removes.
--soft moves the branch and keeps everything else. The removed commit's changes wait on the tray, ready to be committed again, perhaps with a better message:
In the same repository, where the pump checks were added after that fix
git reset --soft HEAD~1
git status -s
git log --oneline
A pumps.txt
2afab73 (HEAD -> main) fix
aba517b First orders
The default (also called --mixed) moves the branch and empties the tray, but leaves the desk alone. The work is still in the files, as changes not yet staged. Here the removed commit had added pumps.txt, so the file is still on the desk, untracked:
In the same repository, where the pump checks were added after that fix
git reset HEAD~1
git status -s
?? pumps.txt
When the removed commit changed a file that git tracks, the default reset lists it:
In the same repository, where the pump checks were added after that fix
echo 'open gate 7' >> orders.txt
git commit -q -am 'Open gate 7'
git reset HEAD~1
Unstaged changes after reset:
M orders.txt
--hard moves the branch and makes the tray and the desk match it. The removed commit's work disappears from your files:
In the same repository, where the pump checks were added after that fix
git reset --hard HEAD~1
ls
git reset --hard ORIG_HEAD
ls
HEAD is now at 2afab73 fix
orders.txt
HEAD is now at e2ac712 Add the pump checks
orders.txt pumps.txt
pumps.txt vanished. The second reset brought it back, because the removed commit still existed: before each reset, git keeps the old position as ORIG_HEAD. But --hard also throws away changes that were never committed, and those no command can bring back. Treat --hard as the one dangerous command in this lesson.
| The situation | Use | History |
|---|---|---|
| undo a commit that has been pushed | git revert | a new commit is added |
| redo your last commit, unpushed, keeping its changes staged | git reset --soft HEAD~1 | rewritten (yours only) |
| take back unpushed commits, keeping the work in the files | git reset HEAD~1 | rewritten (yours only) |
| throw unpushed commits and all changes away | git reset --hard HEAD~1 | rewritten, and work lost |
| take one file off the tray | git restore --staged file | untouched |
Worked example 4
The commit fix closed gate 6 on Sundays, and it has been pushed long ago. Undo it so that the history shows both the change and why it was undone.
What we have: the history First orders, fix, Add the pump checks
What we need: a new commit that removes close gate 6 on Sundays, with a message that gives the reason
The plan: the commit is pushed, so revert, not reset; -n to give the message ourselves; then commit with a title and a body
In the same repository, where the pump checks were added after that fix
git revert -n HEAD~1
git commit -q -m 'Open gate 6 on Sundays again' -m 'The Sunday market has moved to the square, so the lane by gate 6 is clear.'
git show --stat --oneline HEAD
0fc84b6 (HEAD -> main) Open gate 6 on Sundays again
orders.txt | 1 -
1 file changed, 1 deletion(-)
- The new commit removes the one line, and its message says why. The old commit fix is still in the history, so anyone can see both.
Commit 0fc84b6, Open gate 6 on Sundays again, undoes fix without rewriting anything.
Check: cat orders.txt no longer has the Sunday line, and git log still lists fix.
A path that fails: git reset --hard HEAD~2 to go back before fix. It also throws away the pump checks, and it rewrites a history that others already have.
When you are stuck: you are not sure whether to revert or reset
Ask first: has the commit been pushed? If yes, git revert; others hold it.
Not pushed, and you want to redo it: git reset --soft HEAD~1 keeps the changes staged.
Not pushed, and you want the work back in the files: git reset HEAD~1.
Reached for --hard by mistake? git reset --hard ORIG_HEAD goes back, but only to committed work.
Your turn
git reset --soft HEAD~1
git log --oneline | wc -l
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
2
- --soft removes the last commit from the branch.
- Three commits less one is two.
It prints 2.
Why is git revert safe on pushed commits, and git reset not?Tap to reveal
- Which of them changes commits that others already have?
git revert adds a commit; git reset rewrites the branch, which others already have.
After git reset HEAD~1, where are the removed commit's changes?Tap to reveal
- The default reset empties the tray but leaves the desk alone.
In the files on the desk, not staged.
Did you know?
reset, restore and revert
Git's own manual admits the three names are easy to mix up, and sorts them out. It says git revert makes a new commit that reverts the changes of other commits. The command git restore restores files on the desk from the tray or from another commit, and does not change your branch. The command git reset moves your branch's tip to add or remove commits, which changes the history.
Why it fits here: It answers this topic's question: revert adds an undoing commit, restore fixes files, and reset moves the branch.
Reverting a merge needs a side
A merge commit is harder to revert than an ordinary one. The git revert manual says you usually cannot revert a merge, because git does not know which side of the merge should be treated as the main line. The option -m with a parent number, starting from 1, names that side, and the revert then undoes the change relative to that parent.
Why it fits here: It adds a case to this topic's git revert: undoing a merge commit needs -m to say which parent is the main line.
Source: git manual: git-revert
In one line
The command git revert undoes a commit with a new commit, which is safe after a push; give it a message with -n and git commit. The command git reset moves your own unpushed branch back: --soft keeps the tray, the default keeps the desk, --hard keeps nothing.
Setting work aside: the stash
At a glance
Halfway through a change, an urgent fix arrives. The fix must go in alone, without your unfinished lines.
The command git stash puts your unfinished changes aside and leaves the desk clean. Make the fix and commit it, then git stash pop brings your changes back and removes them from the stash. Name an entry with git stash push -m, list entries with git stash list, and add -u to take new, untracked files along too. The stash is a safe shelf for half-done work.
Take a guess: Can you name a stash by how long ago you made it?
You are halfway through a change to the orders: gate 9 is to close, and you have written one line of it. Then word comes that pump 7 must be checked at six, today. The urgent fix must go in alone, without your half-done line. git stash puts your unfinished changes aside and leaves the desk clean:
In the same repository, with half-done work on the desk: close gate 9, added to the orders
git status -s
git stash
git status -s
M orders.txt
Saved working directory and index state WIP on main: e2ac712 Add the pump checks
Before the stash, orders.txt was changed; after it, git status prints nothing. Your change is not lost. Git saved it in a stash entry, named WIP (work in progress) after the branch and the commit you were on. Now make the urgent fix, commit it, and bring your work back with git stash pop:
In the same repository, with half-done work on the desk: close gate 9, added to the orders
git stash -q
echo 'check pump 7 at six' > pumps.txt
git commit -q -am 'Check pump 7 at six'
git stash pop
git log --oneline -1
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: orders.txt
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (7ee30e2e5ff483324a73a7bf913010eacd5f4901)
fd4e996 (HEAD -> main) Check pump 7 at six
git stash pop put the gate 9 line back, printed git status to show it, and then dropped the entry, as the last line says. The urgent commit holds only the pump. Your half-done work is on the desk again, exactly as before.
Naming, listing and looking
With many entries, WIP on main says little. git stash push -m gives an entry a message. git stash list shows the entries, the newest as stash@{0}, and git stash show shows what an entry changes:
In the same repository, with half-done work on the desk: close gate 9, added to the orders
git stash push -m 'half the gate 9 work'
git stash list
git stash show
Saved working directory and index state On main: half the gate 9 work
stash@{0}: On main: half the gate 9 work
orders.txt | 1 +
1 file changed, 1 insertion(+)
| Command | What it does |
|---|---|
git stash, git stash push -m 'msg' | saves the changes aside, and cleans the desk |
git stash list | the entries, newest first: stash@{0}, stash@{1}, ... |
git stash show, with -p | what the newest entry changes, as a stat or a diff |
git stash pop | puts the newest entry back, and drops it |
git stash apply | puts it back, and keeps the entry |
git stash drop | throws the newest entry away |
New files stay behind
A plain git stash takes only the changes to files that git tracks. A new file, never added, stays on the desk:
In the same repository, with half-done work on the desk: close gate 9, added to the orders
echo 'gate 9 plan' > gate9.txt
git stash -q
git status -s
git stash -q -u
git status -s
git stash list
?? gate9.txt
stash@{0}: WIP on main: e2ac712 Add the pump checks
stash@{1}: WIP on main: e2ac712 Add the pump checks
The first stash left gate9.txt behind. With -u (include untracked), the second stash took it too, and the desk is clean. Two entries are now in the list; pop brings back the newest first.
A stash is short-term and local
Stash entries live only in your repository: git push never sends them. They are for minutes or hours, not weeks. For work that will take longer, make a branch and commit it there, as in lesson 03; a branch has a name, a history and a place on the remote.
Worked example 5
You are halfway through closing gate 9 when the pump 7 check must go in at once. Set the half-done work aside, commit the pump fix alone, and bring your work back.
What we have: orders.txt changed (close gate 9, half done)
What we need: a commit with only the pump change, and the gate 9 line back on the desk afterwards
The plan: git stash; change pumps.txt and commit; git stash pop; check the commit and the desk
In the same repository, with half-done work on the desk: close gate 9, added to the orders
git stash -q
echo 'check pump 7 at six' > pumps.txt
git commit -q -am 'Check pump 7 at six'
git stash pop -q
git show --stat --oneline HEAD
git status -s
fd4e996 (HEAD -> main) Check pump 7 at six
pumps.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
M orders.txt
- The commit changed only pumps.txt. After the pop, orders.txt is changed again, with the gate 9 line waiting to be finished. -q kept pop quiet.
The pump fix is fd4e996, alone; the gate 9 work is back on the desk.
Check: git stash list prints nothing: pop dropped the entry.
A path that fails: git commit -am for the pump fix without stashing. The half-done gate 9 line would go into the same commit.
When you are stuck: your stashed work seems to be gone
git stash list shows every entry; stash@{0} is the newest.
git stash show -p stash@{1} shows what an older entry holds.
A new file that you never added was not stashed at all: it is still on the desk, unless you used -u.
Your turn
git stash -q
git stash list
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
stash@{0}: WIP on main: e2ac712 Add the pump checks
- The change to orders.txt goes into a new entry.
- With no -m, the entry is named WIP on the branch, with the commit you were on.
It prints stash@{0}: WIP on main: e2ac712 Add the pump checks.
What is the difference between git stash pop and git stash apply?Tap to reveal
- One of them drops the entry afterwards.
pop puts the work back and drops the entry; apply keeps it.
Does git push send your stash entries?Tap to reveal
- Where do stash entries live?
No: they stay in your repository only.
Did you know?
stash@{2.hours.ago}
The names of stash entries come from the reflog. The git stash manual says the latest stash is stored in refs/stash, and older ones are found in the reflog of that ref. So stash@{0} is the newest entry and stash@{1} the one before. The usual reflog syntax works too, so stash@{2.hours.ago} names the stash as it was two hours ago.
Why it fits here: It answers this topic's question: stash entries use reflog names, so stash@{2.hours.ago} works.
Source: git manual: git-stash
A stash that no longer fits
A stash can wait so long that it no longer applies cleanly. The git stash manual offers git stash branch for that case. It creates and checks out a new branch starting from the commit where the stash was made, applies the stashed changes there, and drops the entry if that works. It is useful, the manual says, when the branch has changed so much that git stash apply fails with conflicts.
Why it fits here: It adds a rescue to this topic's git stash pop: git stash branch puts an old stash back on the commit it came from.
Source: git manual: git-stash
In one line
git stash puts unfinished changes aside and cleans the desk; git stash pop brings them back. Name entries with push -m, list them with git stash list, and add -u to take new files too.
Secrets never go in
At a glance
A password, a key or a token in a repository is a key left in a door. Anyone who can read the repository can use it.
So secrets never go in. Put .env in .gitignore before the first commit, and share only an .env.example, with the names of the settings and no values. If a secret does get in, rotate it first: cancel it and make a new one, because the history and every clone keep the old one, even after the file is removed.
Take a guess: Why do GitHub's tokens start with letters such as ghp_?
A program often needs secrets: a password for a database, a key for a payment service, a token for GitHub, as in lesson 05. Programmers usually keep them in a file of settings, often named .env, read by the program when it starts. The shop has one:
In the shop's repository, with a settings file .env that holds a key
git status -s
?? .env
git sees the file and offers it. One git add . and the key would be in the next commit, and with the next push, on GitHub, where every clone and every fork gets a copy. Anyone who can read the repository can then read the key, and use it.
Ignore the file before anything else
The rule is: the first thing to do with a secrets file is to ignore it. Lesson 02's .gitignore does that. git check-ignore -v then confirms which rule ignores it:
In the shop's repository, with a settings file .env that holds a key
echo '.env' > .gitignore
git status -s
git check-ignore -v .env
?? .gitignore
.gitignore:1:.env .env
git status no longer shows .env, only the new .gitignore. check-ignore names the file, the line number and the pattern: .gitignore, line 1, .env. Commit the .gitignore, so that everyone who clones the repository is protected too. With the rule in place, git refuses to add the file even when asked:
In the shop's repository, with a settings file .env that holds a key
echo '.env' > .gitignore
git add .env
The following paths are ignored by one of your .gitignore files:
.env
hint: Use -f if you really want to add them.
hint: Disable this message with "git config set advice.addIgnoredFile false"
To show others which settings the program needs, commit a file without the secrets, such as .env.example, that holds the names with empty values: TOWER_KEY=. Each person copies it to .env and fills in their own.
When a secret has been committed
Suppose that .env went in anyway, in a commit called Add the settings. You can stop tracking the file with git rm --cached, from lesson 02, which removes it from the tray and keeps it on the desk:
In the shop's repository, where .env, with its key, was committed by mistake
git rm -q --cached .env
echo '.env' > .gitignore
git add .gitignore
git commit -q -m 'Stop tracking .env'
git status -s
ls -a
. .. .env .git .gitignore orders.txt
The desk is clean, and .env is still there for the program. But the history has not forgotten. The earlier commit still holds the file, key and all, and anyone with the repository can read it:
In the shop's repository, where .env, with its key, was committed by mistake
git rm -q --cached .env
echo '.env' > .gitignore
git add .gitignore
git commit -q -m 'Stop tracking .env'
git show HEAD~1:.env
TOWER_KEY=brass-7731
So a committed secret, above all a pushed one, must be treated as known to others. GitHub's documentation gives the order. First, revoke or rotate the secret: cancel the key with the service that issued it, and make a new one, so that the old one opens nothing. Only then, if needed, remove it from the history with a tool such as git-filter-repo. Even that cannot reach other people's clones or forks, which is why rotating comes first.
GitHub also guards the door. Its push protection blocks a push that contains a known kind of secret, such as a token, before it reaches the repository, with a message that says why. GitHub's documentation says it is on by default for your own pushes to public repositories on GitHub.com. Treat it as a last guard, not as the plan: the plan is .gitignore, from the first commit.
| Step | What to do |
|---|---|
| before the first commit | put .env, and any key or password file, in .gitignore; commit .gitignore |
| to share the settings' names | commit .env.example with empty values |
| before each commit | git status: no secrets file listed |
| a secret was committed but not pushed | rotate it to be safe, and remove the commit with git reset |
| a secret was pushed | rotate it at once; then remove it from the history if needed |
Worked example 6
A new project keeps a database password in .env. Set up the repository so that the password can never be committed by accident, while the file stays on the desk for the program.
What we have: .env with a key, untracked; no .gitignore yet
What we need: a committed .gitignore that ignores .env, and a check that git agrees
The plan: write .gitignore; commit it alone; check with git status and git check-ignore
In the shop's repository, with a settings file .env that holds a key
echo '.env' > .gitignore
git add .gitignore
git commit -q -m 'Ignore the settings file'
git status -s
git check-ignore .env
.env
- git status prints nothing: .gitignore is committed and .env is ignored. git check-ignore prints the name of every file that a rule ignores, so .env is safe.
.env is ignored, by a .gitignore that everyone gets.
Check: git add . followed by git status -s lists nothing new.
A path that fails: adding the key file first and planning to ignore it later. The first commit already holds the key, and ignoring a file never removes it from the history.
When you are stuck: you are not sure whether a file is ignored
git check-ignore -v name prints the rule that ignores it, with its file and line, or nothing if no rule does.
A file that git already tracks is not ignored by any rule: git rm --cached it first.
git status -s --ignored lists the ignored files, each with !!.
Your turn
echo '.env' > .gitignore
git check-ignore -v .env
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
.gitignore:1:.env .env
- The rule .env is on line 1 of .gitignore.
- -v prints the file, the line, the pattern, a tab, and the name.
It prints .gitignore:1:.env and the name .env.
A key was pushed to GitHub an hour ago. What is the first thing to do?Tap to reveal
- Can you be sure that nobody has copied it?
Revoke or rotate the key with the service that issued it.
After git rm --cached .env and a commit, is the key gone from the repository?Tap to reveal
- What does the earlier commit still hold?
No: the earlier commit still holds it, and git show can read it.
Did you know?
Tokens that say what they are
GitHub's tokens are built to be spotted. Its blog explained on 5 April 2021 that each token starts with a three-letter prefix, gh and a letter for the type, such as ghp for a personal access token, followed by an underscore. A 32-bit checksum in the last 6 characters lets a scanner reject fake matches. So a leaked token is easy for secret scanners to find.
Why it fits here: It answers this topic's question: the ghp_ prefix and a checksum let scanners find leaked GitHub tokens.
Source: GitHub Blog: Behind GitHub's new authentication token formats
Not filter-branch
Removing a secret from history needs care, and git's own manual names the wrong tool. The git filter-branch manual opens with a warning: the command has a plethora of pitfalls that can mangle the history it rewrites, and poor performance too. It asks people to use another history filtering tool, such as git filter-repo. Rotating the secret still comes first.
Why it fits here: It sharpens this topic's clean-up: git's own manual warns against filter-branch and points to git filter-repo.
Source: git manual: git-filter-branch
In one line
Secrets never go into a repository: ignore .env in .gitignore before the first commit, and share only an .env.example. If a secret does get in, rotate it first, as the history and every clone keep it.
Where it is used
These habits are what make a repository pleasant to inherit. Here is where each one does its work.
| What you learned | Where it is used | A real example |
|---|---|---|
| a title and a body | every commit that others will read | a body that says which complaint led to the change |
| git log --grep and git log -- file | finding why something is the way it is | searching the history for the word market |
| one change per commit | reviews, and undoing one change alone | a pull request of five small, clear commits |
| annotated tags | marking releases | v2.3 tagged, pushed, and published as a GitHub release |
| git revert | undoing a change that others already have | GitHub's Revert button on a merged pull request |
| git reset | tidying your own commits before a push | redoing the last commit with a better message |
| git stash | an urgent fix in the middle of other work | a fix on main while a feature is half done |
| .gitignore for secrets | every project with keys or passwords | .env ignored, and .env.example committed |
Together they answer the Keeper's question from the story: months from now, can a stranger find what changed, why, and how to undo it safely? With these habits, the answer is yes.
Mistakes and debugging
These are the slips that people meet most often with these habits. Every output below is the real one, from the code shown.
1. A message that says nothing
In the shop's repository, with one commit, First orders
echo 'close gate 6 on Sundays' >> orders.txt
git commit -q -am fix
git log --oneline -1
2afab73 (HEAD -> main) fix
A year from now, fix will tell nobody anything. The fix: if the commit is not pushed, rewrite the message with git commit --amend, a title and a body. If it is pushed, leave it, and explain in the next commit or in the pull request.
2. A message given to git revert with -m
In the same repository, where the pump checks were added after that fix
git revert -m 'Open gate 6 again' HEAD~1
echo "[$?]"
error: option `mainline' expects a number greater than zero
[129]
In git revert, -m is the parent to keep when reverting a merge, a number. The fix: git revert -n HEAD~1, then git commit -m with your title and body.
3. git reset --hard over unsaved work
In the same repository, with half-done work on the desk: close gate 9, added to the orders
git reset -q --hard
git status -s
cat orders.txt
open gate 4 at noon
close gate 2
check gate 5
close gate 6 on Sundays
The half-done line close gate 9 is gone, and since it was never committed, ORIG_HEAD cannot bring it back. The fix: before any --hard, run git status. Keep work you may want with git stash or a commit, and reach for --hard only when you truly mean to throw changes away.
4. Forgetting to push a tag
In the same repository, whose main is pushed to origin, the bare repository ../hill.git
git tag -a v1.0 -m 'The spring orders'
git push -q
git ls-remote origin
e2ac712412a2371f1168fa69e0dc957513b7c958 HEAD
e2ac712412a2371f1168fa69e0dc957513b7c958 refs/heads/main
The remote has HEAD and main, and no tags. The fix: git push origin v1.0; afterwards git ls-remote also lists refs/tags/v1.0.
5. git add . with a secrets file
In the shop's repository, with a settings file .env that holds a key
git add .
git status -s
A .env
The key is on the tray, one commit away from the history. The fix: git restore --staged .env now; then put .env in .gitignore, before anything else. If it was already committed, rotate the key, as the history keeps it.
The debugging corner: what does this repository remember?
git log --grep=word finds commits by their message, git log --oneline -- file lists the commits that changed one file, git show commit shows a commit's change, git stash list shows what is set aside, and git check-ignore -v file says which rule ignores a file.
Quick card
The whole lesson on one card. Come back to it whenever you need a reminder.
The lesson in code
echo 'close gate 6 on Sundays' >> orders.txt
git commit -q -am 'Close gate 6 on Sundays' -m 'The Sunday market fills the lane by gate 6.'
git log --oneline --grep=market # find a commit by its message
git tag -a v1.0 -m 'The spring orders' # name a release
git revert -n HEAD # undo it later, as a new commit
git commit -q -m 'Open gate 6 on Sundays again'
echo 'close gate 9' >> orders.txt
git stash -q # set unfinished work aside
git stash pop -q # and bring it back
echo '.env' > .gitignore # secrets never go in
git log --oneline
a060d2f (HEAD -> main) Close gate 6 on Sundays
b47aaa9 (HEAD -> main) Open gate 6 on Sundays again
a060d2f (tag: v1.0) Close gate 6 on Sundays
aba517b First orders
| When you see | It means | Do |
|---|---|---|
fix as a whole message | the reason was never written down | a title and a body, with two -m options |
tag: v1.0 in git log | a tag names that commit | git show v1.0 |
Everything up-to-date after tagging | a plain push sends no tags | git push origin v1.0 |
already exists when pushing a tag | the remote has that tag | tags never move; choose a new name |
You are currently reverting commit | a revert made with -n waits for its commit | git commit with a message, or git revert --abort |
Unstaged changes after reset | the reset kept the work in the files | commit it again, or restore it |
HEAD is now at | a --hard reset changed the files too | git reset --hard ORIG_HEAD to go back |
Saved working directory and index state | your changes are in the stash | git stash pop when you are ready |
The following paths are ignored | a .gitignore rule protects the file | leave it out, as intended |
The story: A drawer that explains itself
You go through the habits that keep a drawer readable. One change to each picture; a first line that says what, and a body that says why; a name for the pictures that matter. Then a way to undo a change without erasing its record, a place to set aside unfinished work, and a rule that secrets never go in at all.
Months later, a new clerk finds why gate 6 was closed on Sundays in thirty seconds, from a note you never thought anyone would read.
The Keeper hands you a brass seal for your own drawers. "The Engine Hall is next," she says, and nods towards the hum beyond the stair. "Their machines answer requests all day. They will want every change written down."
Reagents gathered: commit message, small commits, tag, git revert, git stash, secret.
Sources
- Git reference documentation (the manual pages of git 2.53) (GPL-2 (Debian's copyright file for git 2.53, which covers the documentation with the code; read 2026-11-07); facts and ideas only)
- GitHub Docs (CC BY 4.0 (the github/docs repository's LICENSE, read 2026-11-07); facts and ideas only)