HEAD is detached in repository

2

I'm using NETBEANS and GIT. I made some changes to now at the time the commit is giving this message:

  

HEAD is detached in repository

My repository looks like this:

    
asked by anonymous 10.08.2016 / 01:52

2 answers

3

This means that you are no longer in a local branch (that is, returned to a previous commit or exploring a remote commit).

To return to normal (assuming there are no new changes to commit), simply checkout the branch with which you want to work. For example:

git checkout master
    
10.08.2016 / 10:51
3

This happened because you did a checkout on a commit. You should probably have run this command git checkout a83c7867c2 .

git has a face called HEAD. HEAD points to the current branch. It is through HEAD that we know in which branch we are working. The normal behavior is that HEAD is always pointing to some branch and the branch points to the last commit. By directly checking a commit, HEAD will point directly to a commit. This situation characterizes a detached HEAD.

Anthony Accioly's solution solves your problem.

git checkout master

However, if you have committed some HEAD, and it seems, your commits will be on a separate branch. They will not appear in the master. The solution to this would be to create a branch that points to the last of those commits and then merge with the master. The sequence of commands would be:

  • git checkout -b outra-branch (creating a new branch that points to the commit that HEAD is pointing to)
  • git checkout master (returning to the master branch)
  • git merge --no-ff outra-branch (bringing the changes from the other branch to the master)
  • git branch -d outra-branch (if the branch is no longer needed, it can be removed)
  • If you do not want to lose commits made in a detached HEAD, you should create a branch that points to them. If a checkout is run in a branch, and those commits are released, at some point the git garbage collection will remove them.

        
    23.08.2016 / 04:39