# How to merge two git branches in a pipeline script

**URL:** <https://community.jenkins.io/t/how-to-merge-two-git-branches-in-a-pipeline-script/5208>\
**Category:** Using Jenkins\
**Tags:** git, jenkinsfile, pipeline\
**Created:** [January 4, 2023, 4:11pm UTC](https://community.jenkins.io/t/how-to-merge-two-git-branches-in-a-pipeline-script/5208 "2023-01-04T16:11:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kumar45](https://avatars.discourse-cdn.com/v4/letter/k/d78d45/32.png) [@kumar45](https://community.jenkins.io/u/kumar45)\
**Post date:** [January 4, 2023, 4:11pm UTC](https://community.jenkins.io/t/how-to-merge-two-git-branches-in-a-pipeline-script/5208/1 "2023-01-04T16:11:01Z")

</div>

Hi Guys,

I am unable to find a solution to merge two git branches in a pipeline as script code. Below is my code developed so far to checkout and merge. Only checkout step is working. Please advise what can i need to complete the merge process in one stage.

> stage(“code checkout and merge”) {  
> steps {  
> checkout( [  
> $class: ‘GitSCM’,  
> branches: [[name: “refs/heads/dev”]],  
> userRemoteConfigs: [  
> [credentialsId: ‘test\_key’,  
> url: ‘url.git’]  
> ]  
> ]  
> )  
> }  
> }

Thanks,  
kumar.

---

<div class="post-metadata">

**Author:** ![PierreBtz](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/pierrebtz/32/55_2.png) [@PierreBtz](https://community.jenkins.io/u/PierreBtz)\
**Post date:** [January 4, 2023, 4:18pm UTC](https://community.jenkins.io/t/how-to-merge-two-git-branches-in-a-pipeline-script/5208/2 "2023-01-04T16:18:17Z")

</div>

You probably want to use an `sh` step to directly call `git` commands. This then becomes a git question that you can resolve outside of Jenkins. There are a lot of good resources out there to answer it. You can start with the official git documentation on [Basic Branching and Merging](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging).
