Something went wrong. Try again.
My personal dotfiles, which might provide inspiration for you. Not fit for running directly without forking and changing. www.elliotblackburn.com
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364#!/usr/bin/env bash# Uses "git pull" to grab a github pull request branch from a given remote or origin.# because this uses "git pull" it will either fetch the branch if it doesn't exist,# or update the branch if it does.# # Usage: git pr {remote} {pull-request-id}# git pr upstream 257# git pr 257## Based on https://gist.github.com/gnarf/5406589 and https://gist.github.com/jhnns/d654d9d6da6d3b749986
pull() { local remote="$1" local id="$2" local branch="$3" git fetch -fu $remote refs/pull/$id/head:$branch && \ git checkout $branch && \ git config --local --replace branch.$branch.merge refs/pull/$id/head && \ git config --local --replace branch.$branch.remote $remote;}
pull_pr_if_matched() { if [[ $1 =~ ^(.*):([0-9]+)|(https?://[^/]+/.+)/pull/([0-9]+).*$ ]]; then if [[ -n ${BASH_REMATCH[2]} ]]; then remote="${BASH_REMATCH[1]:-origin}" id="${BASH_REMATCH[2]}" else remote="${BASH_REMATCH[3]}.git" id="${BASH_REMATCH[4]}" fi
branch=pr/$id pull "$remote" "$id" "$branch" return $? fi
echo "$1 doesn't match the pr id pattern." return 1}
test -z "$1" && echo "pr number required." 1>&2 && exit 1
if test "$1" = "clean"; then git for-each-ref refs/heads/pr/* --format='%(refname)' | while read ref; do git branch -D ${ref#refs/heads/} done
elif [[ "$1" =~ ^[0-9]+$ ]]; then remote=${2:-origin} id=$1 branch=pr/$id pull "$remote" "$id" "$branch"
else rc=1 while [ "$1" != "" ]; do pull_pr_if_matched "$1" rc=$? shift done
exit "$rc"fi