sudo chown -R [MY_USER]:[MY_GROUP] .git
When I run into this I just git clone the project into a new file directory and pull the heads folder from located at .git\refs\heads
and replace the original heads file in the directory that your having the problem. Then just delete the new clone you created (since it obviously doesn't have the updates your trying to push).
You want a quick, 100% working solution ?
I tried a few of the ones suggested here (thanks Guys !), but to no fixing the case for me.
rename your directory with _old.
2.git clone your project again, into a brand new directory.
Then , move your files one by one / resume your work.
That's garanteed to work ! - even if playing with git commands looked funnier in the beginning. :)
Note: the spacetime between the "git clone" command and your files will lay on your files only, so beware if you're in the case of several commits and no push done : the commits list (and logic) will be lost.
I had the same problem, today.
I found a very easy workaround to this problem but has a few trade-offs.
I am still not sure what caused it in the first place.
I came across a lot of solutions, and unfortunately, nothing really worked for me.
I could not initialize a GitHub repo during this error, which actually helped me find a solution.
Apparently, just deleting the .git directory solves a lot of issues. Just when I deleted that directory, I was able to initialize a repo.
You shall find the .git folder in your workspace.
.git(dir)/config(file) . the config file may be broken and could be the source of the issue. (I am not sure of the cause, any explanations in laymen would be much appreciated)
just when I deleted the folder, all the errors vanished. I was also able to commit from GitHub desktop (which was throwing me the error, previously, the same error while committing directly from the IDE)
The only downside to this would be, all your staged changes might be lost, that is only it. And you may have to initialize a new repo because giving the same name would throw error(if the same repo already exists)
So, apart from that, you shall be good to go. You can commit changes too now.
–
–
–
–
check branch name
git show-ref --head
Firstly, just checked the error, here you will find which reference is broken
Step 1: just remove this mentioned reference
rm .git/refs/heads/branch_name
Step 2: git fetch
Step 3: git pull
Will work 100% sure....
Then I removed file /my_project_directory/./git/refs/heads/master
and then I can use this command:
git reset --hard <my_hash_of_last_commit_on_remote_branch>
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.