The Mistakes That Bite Beginners
Four mistakes account for most of the real damage beginners do with Git. All four are avoidable by a habit that costs seconds, and all four are worth reading about before you meet them rather than afterwards.
Notice the pattern as you go: in every case Git did exactly what it was told. None of these is a bug, and none of them is prevented by being careful. They are prevented by a habit.
1. Committing a secret
What happens. An API key, a password or a token ends up in a committed file — usually swept in by git add . along with everything else.
What it costs. The moment it is pushed, treat the credential as compromised. Removing the file later does not help: every earlier commit still contains it, and anyone with the repository can read it there. GitHub scans public repositories for leaked credentials automatically, and its own advice when one turns up is to rotate it immediately.
The habit. Write .gitignore before the first commit, and read what git status lists before running git add .. If it happens anyway: rotate first, then git rm --cached, exactly as in Chapter 5.
2. Committing something enormous
What happens. A video, a dataset, or a folder of installed dependencies gets committed. Often it is node_modules, and often it is thousands of files at once.
What it costs. Every clone of that repository carries it forever, because clones bring the whole history. Removing it from the current state does not shrink anything; the file is still in the commits behind you.
The habit. Ignore dependencies and build output on day one. And look at the file count when git status reports it — "3,412 files changed" is not a thing that should ever surprise you.
3. Working directly on main
What happens. Three unrelated changes end up half-finished on the branch that is supposed to hold the working version.
What it costs. None of them can be undone separately, none can be proposed for review, and the version everyone treats as real is broken until whichever one you are furthest through gets finished.
The habit. Branch first, always, even alone, even for a ten-minute change. It is one command, and it is the one that keeps the other three from tangling.
4. Force-pushing over shared work
What happens. A push is rejected, a forum says to add --force, and it works.
What it costs. The branch on GitHub is replaced with yours. Any commit that was there and not on your machine is no longer part of that branch — which, on a shared branch, is somebody's afternoon, and they will find out by discovering their work missing.
The habit. Pull, resolve, push. That is the answer to a rejected push every single time in this book. --force has legitimate uses on a branch nobody else touches, and none of them are things a beginner needs.
All four have near-misses in Sandpiper's story. The club's phone list, committed in week one and cleaned up in Chapter 5. A folder of full-resolution bird photographs that very nearly went in with a careless git add .. An afternoon where three changes were tangled together on main before branching became a habit. And the rejected push in Chapter 7 that a forum would have answered with --force.
The pattern behind all four
In every case Git faithfully did what it was told. Nothing malfunctioned, and no warning was suppressed.
Three of the four are prevented by the same two-second act: reading what git status says before doing something irreversible. The fourth is prevented by not copying a command you do not understand from a forum.
That is the entire safety story of this book, and it is why Chapter 4 is arranged the way it is: diagnose first, type second.
- "A committed secret is fine if I remove it in the next commit." It is in the history, and if it was pushed, assume it has been read. Rotate the credential; that is the only step that actually helps.
- "
--forceis a normal part of working with branches." It has legitimate uses on a branch only you touch. On shared work it is how afternoons disappear, and this book never needs it. - "Working on
mainis fine for small changes." The small change is exactly the one that gets tangled with the urgent thing arriving ten minutes later. - "A large file is only a problem if the repository is public." Every clone carries it, public or private. It is a cost paid by everyone who ever copies the project.
- These four are the mistakes that cost money, time, or someone else's work. Nearly everything else in Git is recoverable, and Chapter 4 covers it.
- Naming the habit beside each mistake keeps this page useful rather than frightening — the point is prevention, not caution.
- Noticing that Git did what it was told in all four cases is what stops you looking for a setting that would have saved you.
Knowledge Check
You have just pushed a commit containing an API key. What is the first thing to do?
- Rotate the credential immediately, treating it as already compromised
- Force-push a corrected version of the branch to overwrite the bad commit
- Delete the repository from GitHub so nobody can clone it any more
- Add the file to
.gitignoreso that later commits do not include it
Why is a large committed file a permanent problem?
- Because clones bring the whole history, so every copy has to carry it forever
- Because GitHub charges per gigabyte once a repository passes a size limit
- Because Git slows down proportionally to the number of files in a project
- Because large files cannot be removed from a repository by any means at all
What is the cost of working directly on main with three changes in progress?
- None of the three can be undone, reviewed or finished separately
- Git refuses further commits until the working directory has been cleaned
- The changes are lost the next time you pull from the remote repository
- The commits cannot be pushed until every change in progress is finished
What is the pattern behind all four of these mistakes?
- Git did exactly what it was told, and a two-second check would have caught it
- Git's defaults are unsafe and each one needs a configuration change to fix
- They all happen because the repository was made public too early
- They are all caused by working with other people rather than alone
You got correct