Last active
August 29, 2015 14:04
-
-
Save ericboehs/cdaa5555b3578e3763f5 to your computer and use it in GitHub Desktop.
Merging github pull requests by ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# These two aliases will allow you to check out the BRANCH that a PR is | |
# associated with by PR ID (gcopr) and also merge a pull request by ID into | |
# master (gmpr). | |
# | |
# I use this in conjunction with the ghi gem to allow me to review and merge pull | |
# requests from the command line. To show open pull requests (I alias this to `prs`): | |
# | |
# ghi list | grep --color=auto '↑' --color=none | |
# Git checkout pull request by ID | |
gcopr() { | |
git branch -D pr-$1 2>&1 | grep -v 'not found.' | |
git fetch origin || kill -INT $$ | |
git checkout master 2>&1 | grep -v "Already on 'master'" || kill -INT $$ | |
git fetch origin pull/$1/head:pr-$1 || kill -INT $$ | |
BRANCH="$(git branch -a --contains pr-$1 | grep -v pr-$1 | tr -d '[:space:]' | cut -f3 -d/)" | |
git branch -D $BRANCH 2>&1 | grep -v 'not found.' | |
git branch -D pr-$1 1>/dev/null | |
git checkout $BRANCH | |
} | |
# Git merge pull request | |
gmpr() { | |
gcopr $1 | |
git checkout master | |
git merge --no-ff -m "Merge pull request #$1 from $BRANCH" $BRANCH && ( | |
git push | |
git branch -D $BRANCH | |
git push --delete origin $BRANCH | |
git remote prune origin | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment