Search code examples
version-controlbitbucket-pipelinesbitbucket-cloud

how to merge from feature branch to the master branch using bitbucket-pipeline.yml file?


Working using feature branches, how can i configure my bitbucket-pipeline.yml file in such a way that the changes are merged to the master branch automatically?


Solution

  • This is what I've done to get a branch merged in master

    #fetch from all branches and mock a user to perform the merge
    - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
      \ && git config user.email "[email protected]"
      \ && git config user.name "git"
    - git fetch origin && git checkout origin/master
    - git merge $BITBUCKET_BRANCH
    

    Finally, if you want to commit the merge, you should add a git push command at the end of the script, likely using a real account for the repository.

    EDIT

    The above solution seems to work only when the user is the owner of the repository.
    Try using the depth option for the pipeline configuration as stated here, to clone the full repository.