Skip to content

Instantly share code, notes, and snippets.

@paulodiovani
Last active September 1, 2015 19:08
Show Gist options
  • Save paulodiovani/148d82e2a8ae894c6c0c to your computer and use it in GitHub Desktop.
Save paulodiovani/148d82e2a8ae894c6c0c to your computer and use it in GitHub Desktop.
Merges branchs or commits from pull-requests as GitHub does
#!/bin/bash
###
# Merge commits or branches as GitHub Pull Requests
#
# Usage: ./merge-pr.sh COMMIT PRNUMBER BRANCHNAME
#
# COMMIT: Commit or branch name to merge
# PRNUMBER: Number of the pull request being merged (used in commit message)
# BRANCHNAME: Branch name being merged (used in commit message)
###
PR=$1
BRANCH=$2
COMMIT=$3
if [ -z "$COMMIT" ] || [ -z "$PR" ] || [ -z "$BRANCH" ]; then
echo "usage: ./merge-pr.sh COMMIT PRNUMBER BRANCHNAME"
exit 1
fi
MESSAGE="Merge pull request #$PR from Codeminer42/$BRANCH"
COMMAND=( git merge --no-ff --strategy-option theirs -m "'$MESSAGE'" "$COMMIT" )
#run command
"${COMMAND[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment