Reputation: 1940
I am trying to checkout a remote branch from git using grdale grgit. This is my code
def gitRepo = Grgit.open(dir: '.')
task checkoutBranch(){
doLast {
gitRepo.checkout(branch: 'remoteTestBranch', createBranch: false);
}
}
It fails with the error "Problem checking out" . This works if I already have a local branch called "remoteTestBranch"
But when I do
git checkout remoteTestBranch
from the command line , it works saying
"Branch remoteTestBranch set up to track remote branch remoteTestBranch from origin.
Switched to a new branch 'remoteTestBranch'"
But the gradle script doesn't work. What am I doing wrong ?
Upvotes: 0
Views: 2137
Reputation: 2578
The following code works for me, please try it:
if(gitRepo.branch.list().find { it.name == 'remoteTestBranch' })
gitRepo.checkout(branch: 'remoteTestBranch')
else
gitRepo.checkout(branch: 'remoteTestBranch', startPoint: 'origin/remoteTestBranch', createBranch: true)
Upvotes: 2