Search code examples
gradlegrgit

Adding commit from one branch to another in a gradle task


My requirement is to add the last commit of branch 'A' to branch 'B'. I did some research and found out 'cherry picking' can be a good solution to this.I want to write a gradle task which will be doing this operation. So, I do something like this:

task CopyCommits() <<{
def grgit = org.ajoberstar.grgit.Grgit.open(dir: project.parent.projectDir)
grgit.checkout(branch: 'B')
'git cherry-pick 2133467'.execute().text.trim()

}

Branch A is my local branch. The above task doesn't perform the required operation.


Solution

  • I was not able to use cherry-pick here since I want to push all commits to the other branch. this worked for me here:

    task PushChanges() <<{
     def grgit = org.ajoberstar.grgit.Grgit.open(dir: project.parent.projectDir)
    'git push origin A:B'.execute().text.trim()
    }