How to merge a PR from command line using hub?
Asked Answered
S

2

8

I'm using git / hub with github following a gitflow workflow in my project and I'm wondering if there's a simple way to avoid entering github to merge and close my pull requests.

The worflow I'm following at the time is this one.

git checkout -b my-feature-123 develop
git add .
git commit -m "my changes"
git push origin my-feature-123
hub pull-request -m "my changes" -b develop
#enter guthub and merge PR
#run deployment 
git checkout develop
git pull origin develop # everything up-to-date

So I want to replace the #enter guthub and merge PR part with a command line merging command, till now nothing seems to work.

Salmonella answered 28/12, 2018 at 14:42 Comment(0)
C
11

It should be possible to merge the feature branch from the command line using git's merge command. First, you'll need to checkout the branch you are merging to which in this case is develop:

git checkout develop
git merge --no-ff my-feature-123
git push

The --no-ff is used to prevent a fast-forward merge which is the behavior you'd want for gitflow.

Confirmatory answered 28/12, 2018 at 14:51 Comment(3)
that's a good alternative. What I'm really looking for is to merge the pull-requestSalmonella
Actually this seems to do the trick, a few more testings before green tickSalmonella
the only modification I'd do is git push origin develop at the last commandSalmonella
R
3

This is not possible via a hub command dedicated for pull requests and performing merges.

However, it can be done using hub-api and Pulls API using the following script (source):

#!/bin/bash

# Usage: hub-pr-merge <PR-NUMBER>
#
# Cause a pull request to be merged into its respective base branch.
#
# Author: Oliver Joseph Ash

# If a script errors, force the script to fail immediately.
set -e

ID=$1
shift 1

# https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
hub api -XPUT "repos/{owner}/{repo}/pulls/$ID/merge" "$@"
Readjustment answered 28/4, 2020 at 7:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.