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.