Niel de Wet
Niel de Wet

Reputation: 8398

IntelliJ error: branch 'origin/HEAD' does not point at a commit, some refs could not be read

As far as I can tell everything in my git local repository is fine. I can commit, push, pull, whatever I like.

However, when I view the details of a commit in the IntelliJ log, the Contained in branches:

Can not load branches due to error:
error: branch 'origin/HEAD' does not point at a commit 
error: some refs could not be read 
error: branch 'origin/HEAD' does not point at a commit 
error: some refs could not be read

What could have caused this and how do I fix it?

Upvotes: 11

Views: 4895

Answers (1)

user456814
user456814

Reputation:

origin/head sounds like it refers to the default branch set in your remote origin repo. For example, when I do git branch -a, I see this show up in the list:

remotes/origin/HEAD -> origin/master

You might be missing this reference in your local repo, or your local repo's reference might be out of date, if the default branch is changed in the remote, and the old default is deleted.

Possible Solution

If this is indeed the cause of your IDE error, then you can manually correct it using git symbolic-ref:

git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/<default-branch>

Where <default-branch> is the branch that is default in your remote repo.

Updated Solution

So git actually has a more convenient command that can be used to update a local repo's symbolic-ref to the default branch in a remote repo:

git remote set-head <remote> --auto

# Or shorter
git remote set-head <remote> -a

It was introduced in commit bc14fac for git 1.6.3 (May 2009).

Sets or deletes the default branch ($GIT_DIR/remotes/<name>/HEAD) for the named remote.
Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch.
For example, if the default branch for origin is set to master, then origin may be specified wherever you would normally specify origin/master.

Upvotes: 22

Related Questions