Failed to set refs / heads / master on commit

Yesterday I was able to fix the penalty. But today (I did not change anything), when I commit:

$ git add config.h $ git commit -m "Update config.h to reset the values" error: Couldn't set refs/heads/master fatal: cannot update HEAD ref 

I know that this error can also occur during pull or push. But I did not find a solution to fix this when committed.

My .git / config file looks like this:

 [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly [remote "origin"] url = git@SOME _URL fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master 
+8
source share
4 answers

You seem to have lost your HEAD , so you have to recreate it. You can do it using this.

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

This will create a HEAD file in your .git folder. This should solve your problem.

Also try running the git fsck command. It checks the connectivity and reliability of objects in the database.

 git fsck --lost-found 

Use this to scan unreachable objects. It will write dangling objects in .git/lost-found/commit/ or .git/lost-found/other/ , depending on the type. If the object is a blob, the contents are written to the file, not its object name.

+9
source

It may help others; I waited about a minute and just repeated the fixation and ... it worked.

+2
source

Check the .git folder for the HEAD file.

 $ cat .git/HEAD ref: refs/heads/master 

If this does not exist, create it.

 $ echo "ref: refs/Heads/master" > .git/HEAD 
0
source

In my case, the problem was with the resolution in the GIT repository on the server for the path refs/Heads/master .

After resolving my username to access the specified path, everything worked fine.

0
source

Source: https://habr.com/ru/post/989027/


All Articles