Skip to content

Instantly share code, notes, and snippets.

Created Mar 11, 2021
What would you like to do?
set -e
[[ $# == 1 ]] || {
echo "usage: $0 <pr-number>"
exit 1
upstream=$(git remote -v | grep -E '^upstream\s+' | head -1 | sed 's/upstream.*\(.*\)\.git.*/\1/')
git fetch upstream pull/$pr/head -f
git checkout pr$pr 2> /dev/null || git checkout -b pr$pr
git reset --hard FETCH_HEAD
prInfo=$(curl -s$upstream/pulls/$pr)
remoteName=$(echo -E $prInfo | jq -r '.head.user.login')
git remote -v | grep -E "^$remoteName\s+" > /dev/null || {
remoteUrl=$(echo -E $prInfo | jq -r '.head.repo.ssh_url')
echo "Adding remote $remoteName - $remoteUrl"
git remote add $remoteName $remoteUrl
branch=$(echo -E $prInfo | jq -r '.head.ref')
git fetch -f $remoteName $branch
echo "Push changes with:"
echo git push -f $remoteName HEAD:$branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment