This morning we pulled from our repo, and git put us on (no branch).
I don’t understand this, why did this happen? And how to get out of it without losing our changes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
“Not currently on any branch” means you have a detached head, i.e. your HEAD pointer is directly referencing a commit instead of symbolically pointing at the name of a branch.
You can get into this situation by checking out a commit by SHA1, or when you’re in the middle of a rebase, or when a merge fails. It’s hard to say what you may have done to get into this situation by accident.
It’s said that you may lose your changes when you switch from a detached HEAD to some branch, but the reflog will always keep track of where your HEAD moved. In fact, Git 1.7.5 will warn you when switching from a detached HEAD will lose commits. The only time you can really lose work is when you have uncommitted changes, which you may want to commit or stash.
A simple way to see what happened is
git reflogorgit log -g --decoratefor a more verbose listing. The--decorateoption will label every SHA1 with the names of all the branches that point at it. If the SHA1 of your current HEAD is exactly the same as master, then you don’t have to do anything butgit checkout masterto get back on track. Otherwise, see if the SHA1 is pointed to by some other branch. If not, you may wish to create a branch to hang on to it.Another good command is
git branch -av, which will similarly list all branches and what they point to, so you can see what your(no branch)is really supposed to be.