Git Branching: Start a Branch Before You Commit
Fourth day, and Teo walks past her desk with coffee, looks one second at her terminal, and stops walking.
"You are on main," Teo says.
"I am careful," Niki says, a little defensive.
"You are on main."
Forty minutes of uncommitted work, directly on main, again. At university everybody worked like this, one branch, one folder, and if something risky needed trying, you copied the whole project into a second folder. She knows a colleague from those days who is a senior developer now and still works this way.
Teo does not tell her how to fix it. He tells her the work is not lost, git almost never loses anything for real, and that she should find how to move it to a proper branch without dropping it.
Off main, Work Still Attached
The uncommitted change to auth/token.go does not care which branch is checked out, it just sits in the working tree until something is done with it. A new branch takes her off main without touching that file at all, the change comes along for free.
Teo's tip
git switch -c <branch-name> creates a new branch from wherever you currently are and switches to it in one move. Uncommitted changes are not tied to any branch, so they stay in the working tree exactly as they were.
Now It Gets a Commit
Sitting on a feature branch does not fix anything by itself, the change still has to become a real commit, on this branch, not on main. main stays exactly where it was, three commits, nothing more.
Teo does not check the branch name. He checks git log main..HEAD once, sees it is not empty, and goes back to his coffee.