Home·Error messages

git · Git

The message

Warning: you are leaving 1 commit behind, not connected to any of your branches:

What it means

It warns that you committed while in detached HEAD and are now leaving, with no branch pointing at those commits. It happens when you checked out a commit hash, worked, committed, and then went back to a branch. Use the hash printed in the message: git branch rescue 8a3f21c pins them to a name, and that command changes nothing else — it only adds a name. If you already left, git reflog still lists them, but commits nothing points at are removed once garbage collection runs, which by default means roughly thirty days.

The fix

git branch rescue 8a3f21c
Printed by
git
Git
29

Almost every git error is a refusal that means "doing that from this state would lose something"; fatal: means git stopped without changing anything, and the hint: lines under the first line usually carry the actual remedy.

Reading an error message

  • Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
  • If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
  • Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
  • The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
  • Before pasting a fix, check what it throws away. Some of these cannot be undone.

Common questions

Q. What does “Warning: you are leaving 1 commit behind, not connected to any of your branches:” mean?

It warns that you committed while in detached HEAD and are now leaving, with no branch pointing at those commits. It happens when you checked out a commit hash, worked, committed, and then went back to a branch. Use the hash printed in the message: git branch rescue 8a3f21c pins them to a name, and that command changes nothing else — it only adds a name. If you already left, git reflog still lists them, but commits nothing points at are removed once garbage collection runs, which by default means roughly thirty days.

Q. How do I fix it?

git branch rescue 8a3f21c — before running it, check the explanation above for what this command discards.

Q. Which tool prints this?

git. It sits under Git, and the message runs to 14 words.

Errors nearby