Reputation: 2523
I recently noticed that our git server has a branch called HEAD. I've tried doing this locally and git warns me that this is ambiguous. Are there any potential horrible problems we could encounter by deleting/renaming this branch?
Upvotes: 7
Views: 2788
Reputation: 6982
Creating a remote branch called HEAD
is possible, and does not seem particularly harmful:
~/code/foo/bar (master) $ git push origin master:HEAD
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]:foo/bar
* [new branch] master -> HEAD
~/code/foo/bar (master) $ git branch -a
* master
remotes/origin/HEAD
remotes/origin/master
~/code/foo/bar (master) $ git push origin :HEAD
To [email protected]:foo/bar
- [deleted] HEAD
~/code/foo/bar (master) $ git branch -a
* master
remotes/origin/master
Creating a local branch called HEAD
has nastier effects:
~/code/foo/bar (master) $ git checkout -b HEAD
Switched to a new branch 'HEAD'
Your branch is up-to-date with 'origin/master'.
~/code/foo/bar (HEAD) $ git checkout -b fubar
warning: refname 'HEAD' is ambiguous.
fatal: Ambiguous object name: 'HEAD'.
~/code/foo/bar (HEAD) $ git branch -a
* HEAD
master
remotes/origin/master
~/code/foo/bar (HEAD) $ rm .git/refs/heads/HEAD
~/code/foo/bar (HEAD*) $ git checkout master
Switched to branch 'master'
All of the above was with git version 2.3.0 installed via Homebrew on OS X.
It is easy to type many of the above invocations by accident, and unfortunately Git does not fail fast when Edit: Newer versions of Git do now fail fast with HEAD
(or FETCH_HEAD
) is specified in a place where the special meaning does not apply.HEAD
. For example, with git version 2.22.0:
~/code/foo/bar (master) $ git checkout -b HEAD
fatal: 'HEAD' is not a valid branch name.
But a branch called FETCH_HEAD
is still allowed.
Upvotes: 2
Reputation: 87493
It is normal for a bare repo to have a 'HEAD'. Keep in mind that HEAD is not a normal branch, but rather it is a pointer to a branch.
Upvotes: 2
Reputation: 239220
Your server should have a branch pointer called HEAD
, which will point to your default branch. By default, git branch -r
will show you this:
origin/HEAD -> origin/master
Upvotes: 6