fatal: Failed to resolve HEAD as a valid ref

Repost of: http://stackoverflow.com/questions/37594459/fatal-failed-to-resolve-head-as-a-valid-ref

I am getting fatal: Failed to resolve HEAD as a valid ref. whenever I try to commit.

I have tried

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

but its not working

Also tried

git commit

its not working either from below sources

Git 'fatal: No such ref: HEAD' 

git tag: fatal: Failed to resolve 'HEAD' as a valid ref

Please help in..All my commit history is also gone

1 answer

Sounds like your repository got corrupted. If you have it pushed to a remote, you can re-clone, then copy any changes you've made from the old working copy to the new.

do you mean re clone and then copy paste made changes to working directory manually?

You can re-clone then copy > paste your entire directory with the changes into the new clone directory and do git status to confirm all your changes were copied.

What do you see in the output from git reflog?

I had a git in a dropbox folder once that got corrupted because of dropbox. Got into the habit of having both a real remote remote and a 2nd remote pointing to another clone on the same machine and pushing to both so just in case one gets corrupted I can just clone the other local one and if my house burns down I still have the remote in the cloud also.

oh that's the good idea to replace complete root folder with newly cloned....

git reflog showin "fatal: your current branch appears to be broken" 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

649 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you