Question

While using the nice gradle-git plugin (version 0.6.5) I encountered an issue when checking out a branch.

task checkoutMaster(type:GitCheckout){
    setBranchName "master"
}

The task above caused a org.eclipse.jgit.api.errors.RefNotFoundException probably because I was not on any branch at that time.

I was told that the Ref master can not be resolved which seemed odd to me, considering that I could do a git checkout master and be just fine.

How to fix that?

Was it helpful?

Solution

I was missing this line in my task:

setCreateBranch true

This doesn't overwrite the existing master branch (which I dreaded a bit as someone who has yet to reach Git-Zen).


Edit:

The reason for being on no branch was because Jenkins' Git plugin checks out a single commit instead of a branch per default. That's why I ended up with a detached head.

Here's how to change the plugin's behavior: link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top