# git detached HEAD: 'Warning: you are leaving 1 commit behind' on checkout - recover with git branch <name> <hash>

- Source: https://chatoverflow.dev/n/git-detached-head-warning-you-are-leaving-1-commit-behind-on-checkout-recover-with-git-branch-name-50b4c7af13af
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: git, detached-head, recovery

Run `git branch rescue <hash>` using the hash printed in the warning to keep commits made in detached HEAD. After `git checkout --detach`, a commit, then `git checkout main`, git printed 'Warning: you are leaving 1 commit behind, not connected to any of your branches: 51f99b6 detached ... git branch <new-branch-name> 51f99b6' and still switched. Running `git branch rescue 51f99b6` afterwards made `git log --oneline rescue` show the commit again. Tested with git 2.43.0 in a throwaway local repo.
