Skip to main content

Troubleshooting — The Librarian's Problem Desk

Everyone eventually sees a scary Git message. This is the Problem Desk: what the message means, why it happened, and how to get out. Each problem follows the same Problem → Cause → Fix rhythm you know.

1 · "You are in 'detached HEAD' state"​

Problem

Git prints a long warning, and you feel like you broke something.

Cause: You ran git checkout <some-commit-hash> (like in Exercise 4). HEAD — the name on your notebook — is now pointing at a past commit with no branch. You're standing in the past, not on any named branch.

Fix: Nothing is lost. Get back to a branch:

Return to a branch
git switch main

Or, if the work you did in the past is worth keeping, name it:

Give the past a branch name
git switch -c feature-from-past
Remember

Detached HEAD = "you are in the past with no notebook name." Creating a branch before adding commits prevents losing work.

2 · "You have unstaged changes" — can't switch branches​

Problem

git switch refuses and mentions your uncommitted changes.

Cause: Your working copy has changes that would collide with the branch you're moving to. Git won't risk the mess.

Fix (choose one):

Option A — commit it
git add .
git commit -m "Save current work"
Option B — put it in the drawer for now
git stash
Option C — throw it away (if you don't want it)
git restore .

3 · "fatal: not a git repository"​

Problem

Git commands fail immediately with this error.

Cause: You're in a folder that isn't inside a repository — usually the wrong directory, or you never ran git init/git clone there.

Fix:

Check where you are and look for .git
pwd
ls -a

Then either move into the right folder, or open a register here:

Make this folder a repository
git init

4 · "non-fast-forward" — push rejected​

Problem

git push is rejected and mentions non-fast-forward or fetch first.

Cause: The central library has commits you don't have yet. You're trying to push pages built on a stale copy.

Fix:

Get the latest, then push again
git pull
git push

If the pull creates a conflict, resolve it like in Exercise 3, commit, then push.

5 · Typo or missing file in my last commit​

Problem

The last commit message is wrong, or a file was left out.

Cause: You committed too fast. Happens to everyone.

Fix (only if not pushed yet):

Fix the message
git commit --amend -m "The correct message"
Add a forgotten file
git add the-file
git commit --amend --no-edit
Careful

Don't amend a commit your teammates already pulled — use git revert instead. See the Rescue Toolkit.

6 · "Please tell me who you are"​

Problem

Git refuses to commit because it doesn't know your name.

Cause: You never ran git config after installing Git (skipped Exercise 0).

Fix:

Tell Git who you are (once)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Still stuck?​

The Problem Desk always starts with the same two tools:

Ask where you are
git status
Read the last few diary entries
git log --oneline -5

If you can answer "which branch am I on?" and "what's the last commit?", the fix for almost any problem becomes obvious. And if a term still confuses you, the Glossary is one click away.