Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Detached HEAD in remote BitBucket repo

Darren Houle
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 10, 2018

One of my developers (no longer at my company) managed somehow to create a branch called HEAD on our BitBucket server (v4.14.0). Either that or it's not a true branch but displaying as a branch because it's a reference to the head of Master. Not sure but nothing I do seems to move it or fix it.

BB Network Detached HEAD.PNG

 

BB HEAD behind HEAD.PNG

In SourceTree > Terminal

$ git branch -r
origin/HEAD -> origin/master
origin/development
origin/master

$ git remote show origin
* remote origin
Fetch URL: http://username@bitbucket.mycompany.org/scm/isc/cms-machine-readable-json.git
Push URL: http://username@bitbucket.mycompany.org/scm/isc/cms-machine-readable-json.git
HEAD branch: master
Remote branches:
development tracked
master tracked
Local branches configured for 'git pull':
development merges with remote development
master merges with remote master
Local refs configured for 'git push':
development pushes to development (local out of date)
master pushes to master (up to date)

Sounds like a detached head but every blog I find describes how to fix this locally in SourceTree, but I cannot clone or check out HEAD to local, it says it's ambiguous (apparently references both the hash of a commit and the head of the master branch?) I also cannot merge HEAD into Master or delete HEAD in BitBucket for the same reason.

I know I can create a brand new repo and drop in the latest files, but I'll lose all the change history in the current repo, I'd rather not do that. I also want to know how this happened so we can void it in the future. Any ideas how to fix this?

 

2 answers

0 votes
hit jethva
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 13, 2024

It sounds like the HEAD reference in your BitBucket repo is causing confusion because it's pointing to the head of master and being misinterpreted as a branch. To resolve this, you can try using the command git symbolic-ref HEAD refs/heads/master to correctly point HEAD back to the master branch. This should prevent the ambiguity and allow normal operations on the repository. Additionally, always double-check your repository configuration to avoid such issues in the future. For more details on handling detached HEAD issues, you can refer to this guide.

0 votes
etechman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 6, 2019

The solution is here you have a detached head which is not supported and you need to related it back to the master branch to activate the branch properly. I would copy the contents out of the branch in case you need to save any work that was done. 

https://confluence.atlassian.com/bitbucketserverkb/detached-heads-are-not-currently-supported-779171792.html

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events