Jenkins: Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref

I’ve moved some of my projects from SVN to GIT. In Jenkins, builds are working fine but when I try to release, I get the following stack trace

I think this is a common issue sometimes occur when we try to release a project in Jenkins though the project itself may be successfully built when we run the build using link “Build Now”.

For example, you have the project in GIT repository and there you have branches like “develop” and “master”. When you want to release the project for deploying on Dev, SIT and UAT, you would like to build and release from “develop’ branch, and when you want the project for production release then you would like to build and release from “master” branch. Therefore, you want to click on “Perform maven release” in Jenkins to release an artifact for the project either from “develop” or “master” branch and you may face the error similar to the following

“Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref”

So I was also trying to release the project in Jenkins from “develop’ branch and spontaneously I was getting the above error but I did not find any satisfactory solution in Internet and thereafter I was trying to resolve the issue in different approaches and finally after few hours by doing some trial/error I got a solution that helped me to release the project from “develop” branch successfully.

The whole stack trace could be similar to the below

I think that by default Jenkins does the checkout without naming the branch which produces this error. By default, Jenkins GIT plugin builds on a detached HEAD, not on a branch. You can use the option named Checkout to specific local branch (optional) inder Additional Behaviours to make Jenkins create a local branch and do your release work.


  1. In Jenkins job, click on Configuration link, then search for Additional Behaviours. Then click on Add and select “Checkout to specific local branch” and put “develop” in the input box (if you are releasing from “master” branch then put “master” => mainly for production release). Then click on “Save” at the bottom.
  2. Please do not use your username/password or credentials, letting SSH take over while you are releasing the project in Jenkins using the link “Perform maven release”.

Please note that my Jenkins version is 1.651.

Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.