Git Detached Head

The problem of git detached head

In this post, we will study how we can use commands other than git pull for the same purpose that causes git detached head. This problem can cause the issue of a detached head. A command that one can do is:

 

 

it checkout HEAD^ src/

 

 

here src means the directory consisting of the deleted files. One can also find a detached head in it. 

 

 

Solution

Users are no longer on a branch if they have checked out just one commit in the history and have a detached head. For executing the below command one needs to check the branch on which they were working:

 

 

git checkout master

 

 

If one want to restore the file and want to delete it then one can follow the below command:

 

 

git checkout -- path/to/foo

 

 

If one wish to maintain the modifications connected to the detached HEAD. 

  • Run git branch tmp to store your modifications in the new tmp branch.
  • Execute git checkout master.
  • Run git merge tmp from the master branch if you want to merge your modifications into the master branch. Git checkout master should place you on the master branch.

These functionalities are basically important for solving the issue of git detached head. These are solutions are available for solving the above issue.  

 

 

Also Read: How do you get a timestamp in JavaScript?

 

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *