Skip to main content


A detached HEAD in Git happens when you check out a specific commit, tag, or remote branch without being on a local branch. Instead of pointing to the tip of a branch, HEAD points directly to a commit. This is called a "detached" state. While in this mode, any changes or commits you make aren’t associated with a branch. If you switch to another branch, those commits can be lost unless you manually create a new branch from that point. To exit safely, either check out an existing branch (git checkout main) or save your current state with git checkout -b my-temp-branch. This ensures your work is preserved. Detached HEAD is useful for testing, debugging, or viewing history, but it’s important to understand its risks when making changes.