Current Git branch is HEAD detached at

Article ID:227266408
1 minute readKnowledge base

Issue

When you try tagging or pulling your code Git returns an error like:

current Git branch is HEAD detached at 0ff123e

Environment

  • CloudBees Jenkins Enterprise

  • Git Plugin

Resolution

When the Jenkins Git plugin clones a repo, it checks out a specific commit, rather than HEAD of the repo. This puts the repo in a "detached" state, so if you want to perform further git operations on the repo you need to attach to a branch with a checkout command in a shell step.

 git checkout ${BRANCH_NAME}

From the git checkout documentation:

--detach

Rather than checking out a branch to work on it, check out a commit for inspection and discardable experiments. This is the default behavior of "git checkout <commit>" when <commit> is not a branch name. See the "DETACHED HEAD" section below for details.
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.