3

I'm fairly new to git. Currently I try to follow this tutorial to overlay the icon of my app with branch name and version: http://www.merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/

I get however an error when executing

git rev-parse --abbrev-ref HEAD
warning: refname 'HEAD' is ambiguous.
error: refname 'HEAD' is ambiguous

googling brought up some results suggesting that this happens when there is a branch named 'HEAD' - but I don't think that's the case. At least in the online repository on bitbucket I don't see any branch labeled 'HEAD' and querying it through the terminal yields:

git branch -r
origin/#224-Push-notifications
origin/1.0.2
origin/HEAD -> origin/master
origin/app-forced-update
origin/master
origin/milestone6
origin/staging


git branch
* #224-Push-notifications
1.0.2
HEAD
master
milestone3
milestone4
milestone5
milestone6

not sure why on the remote HEAD there is a -> while on the local HEAD there is none. maybe that's the problem?

also, searching for HEAD in the .git folder yields

find .git -name HEAD
.git/HEAD
.git/logs/HEAD
.git/logs/refs/heads/HEAD
.git/logs/refs/remotes/origin/HEAD
.git/refs/heads/HEAD
.git/refs/remotes/origin/HEAD

anyone understands what's the issue and how I can cleanly resolve it?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
matthias_buehlmann
  • 4,641
  • 6
  • 34
  • 76
  • Note: With Git 2.16, a branch named HEAD won't be possible anymore (at least, you won't be able to create new ones). See [my answer here](https://stackoverflow.com/a/47581080/6309) – VonC Nov 30 '17 at 19:26

3 Answers3

4

You've got a local branch called HEAD, so git doesn't know whether you're referring to that or the HEAD, which is the latest commit in the current branch. It's not a good idea to name a branch HEAD, so you should delete it: git branch -D HEAD. This'll fix the rev-parse error.

origin/HEAD -> origin/master in the remote branches is a remote-specific thing that means the master branch will be checked out when you clone from the remote.

desbo
  • 677
  • 7
  • 14
  • hmmm - how could it happen that I have a local branch named HEAD? I definitely never created one manually – matthias_buehlmann Jan 24 '14 at 15:17
  • @user1282931 Is there any chance that you've run something like `git checkout -t origin/HEAD` or used any GUI option that amounts to the same thing? –  Jan 24 '14 at 15:19
  • It would've been created somewhere along the way. Try `git reflog | grep checkout` and look for something like `checkout: moving from somebranch to HEAD` - that's the local branch being created – desbo Jan 24 '14 at 15:23
  • This can also happen if you have a tag named 'HEAD'. I've made the mistake of doing `git tag HEAD 1.0.0 ...` and put myself in this situation. – daraul Apr 18 '20 at 01:29
4

The results of git branch show that you have a brach called HEAD. Looks like you inherited it from origin.

You can safely remove it from your copy using

git branch -d HEAD
Alex Brown
  • 41,819
  • 10
  • 94
  • 108
0

It's thinking that local is copy of remote, which always as a current is marked HEAD. When it isn't it don't know how to treat it. Locally or Pull from remote. You can change name for local HEAD, by

git branch -m HEAD newbranch
pomaranga
  • 1
  • 2