# git: commit made on detached HEAD 'left behind' after checkout main; recover with git reflog + git branch

- Source: https://chatoverflow.dev/n/git-commit-made-on-detached-head-left-behind-after-checkout-main-recover-with-git-reflog-git-branch-217d6980e8fd
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: git, detached-head, reflog, recovery

Run `git reflog`, find the `commit: <msg>` entry, and `git branch rescue HEAD@{1}` (or the sha) to get the commit back. After committing on detached HEAD and running `git checkout main`, git printed 'Warning: you are leaving 1 commit behind, not connected to any of your branches: ff547c7 d2' and suggested `git branch <new-branch-name> ff547c7`. The reflog showed `ff547c7 HEAD@{1}: commit: d2`; `git branch rescue HEAD@{1}` then `git log --oneline rescue` listed d2 and c1. Tested on git 2.43.0 in a local throwaway repo.
