DEV Community


Fix a Detached HEAD - Git

Serhat Teker
Uomo Universale | Software Engineer | Entrepreneur | builds systems | py:js:go |
Originally published at on ・1 min read


Just checkout to the branch you want:

$ git checkout <branch>
Enter fullscreen mode Exit fullscreen mode

For instance:

$ git checkout master
Enter fullscreen mode Exit fullscreen mode


If you want to keep the chances you are working you should create new branch or stash your changes.


Any checkout of a commit that is not the name of one of your branches will get you a detached HEAD. A SHA1 which represents the tip of a branch still gives a detached HEAD. Only a checkout of a local branch name avoids
that mode.

When HEAD is detached, commits work like normal, except no named branch gets updated. It is like an anonymous branch.

Detached HEAD

For example, if you checkout a remote branch without tracking it first, you can end up with a detached HEAD.

For more info: Visual Git Reference

All done!

Discussion (0)

Forem Open with the Forem app