Skip to content

Instantly share code, notes, and snippets.

@joshdholtz
Last active November 10, 2020 14:52
Show Gist options
  • Save joshdholtz/fd95b29b206e8932563a936aed807e0f to your computer and use it in GitHub Desktop.
Save joshdholtz/fd95b29b206e8932563a936aed807e0f to your computer and use it in GitHub Desktop.
gh pr push <pr_number>
# Pushes to the remote that the PR was created from
# Useful for open source projects that allows maintainers to edit
# Requires "brew install jq"
# Requires "brew install github/gh/gh"
function pr_push {
ORG_AND_REPO=$(git remote get-url origin | sed 's/.*\/\([^ ]*\/[^.]*\).*/\1/')
REMOTE_URL=$(curl https://api.github.com/repos/$ORG_AND_REPO/pulls/${1:?"The PR number must be specified"} | jq .head.repo.clone_url | tr -d '"')
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Going to execute: git push $REMOTE_URL $BRANCH"
$(git push $REMOTE_URL $BRANCH)
}
# Push equivalent of https://cli.github.com/manual/gh_pr_checkout
# gh pr push <pr_number>
gh() {
if [ "$1" = "pr" ] && [ "$2" = "push" ]; then
pr_push $3
else
command gh "$@"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment