diff --git a/README.md b/README.md index e02aa3697f..e700e5c5f8 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ configuration: [git](http://git-scm.com/) configuration: +- Adds a `co-upstream-pr $PR_NUMBER $LOCAL_BRANCH_NAME` subcommand to checkout remote upstream branch into a local branch. - Adds a `create-branch` alias to create feature branches. - Adds a `delete-branch` alias to delete feature branches. - Adds a `merge-branch` alias to merge feature branches into master. diff --git a/bin/git-co-upstream-pr b/bin/git-co-upstream-pr new file mode 100755 index 0000000000..f427e8d9b4 --- /dev/null +++ b/bin/git-co-upstream-pr @@ -0,0 +1,24 @@ +#!/bin/sh + +set -e + +pull_request_number=$1 +local_branch_name=$2 + +if [ -z "$pull_request_number" -o -z "$local_branch_name" ]; then + echo "usage: git co-upstream-pr " + exit 1 +fi + +if git remote -v | grep -q upstream; then + git fetch upstream "pull/$pull_request_number/head:$local_branch_name" + git checkout "$local_branch_name" +else + cat <