Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git 'fatal: No such ref: HEAD'

A weird thing happend to my git repository. When I try to commit something in tortoisegit window I receive all files from project. I cannot revert them, when I pull from server I receive fatal: No such ref: HEAD and fatal: Cannot lock the ref 'HEAD'. All my local branches are missing. Is there any way to resolve the problem?

This is not first commit or something. This thing happend suddenly.

EDIT:

git branch -a says: Failed to resolve HEAD as a valid ref

git status prints all project files marked as new file.

I changed repository folder name for a while, and when I changed it back things were not correct.

like image 322
szaman Avatar asked Jan 31 '11 07:01

szaman


People also ask

How do I find my git origin?

If you've copied a project from Github, it already has an origin. You can view that origin with the command git remote -v, which will list the URL of the remote repo.

What is git remote prune?

The git prune command is an internal housekeeping utility that cleans up unreachable or "orphaned" Git objects. Unreachable objects are those that are inaccessible by any refs. Any commit that cannot be accessed through a branch or tag is considered unreachable.

What is the pull command in git?

The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content.


1 Answers

You've lost your HEAD so you'll need to recreate it. The simplest thing to do is this.

echo ref: refs/heads/master >.git/HEAD 

Now you should be able to run other git commands and see where you're at.

(Although, in theory, you could attempt to do git symbolic-ref HEAD refs/heads/master newer git versions don't recognize a .git as a git repository unless it already contains a HEAD so this won't work to create a new one.)

like image 132
CB Bailey Avatar answered Sep 28 '22 00:09

CB Bailey