1. Andrew Hagedorn
  2. Articles
  3. Open Github to Create a PR from the Command Line

Open Github to Create a PR from the Command Line

Andrew Hagedorn, October 2020

This is an archive of the random commands I have found useful. You may or may not, but the next time I need them I will know where to find them.

My team uses Github for reviewing pull requests prior to merging in code. This script avoids navigating to github and finding your branch and dumps you automatically into the PR creation flow for the current branch of the repository you are in:

function pr {
    REPOURL=$(git config --get remote.origin.url)
    REPOURL=${REPOURL/.git/}
    REPOURL=${REPOURL/git@github.com:/}
    BRANCH=$(git rev-parse --abbrev-ref HEAD)
    BODY="@CodeReviewrsYouWant"$'

'"Description"$'
'"==="$'
'"Some description"
    URL="https://github.com/$REPOURL"
    URL="$URL/compare/master...$BRANCH?expand=1&body=$BODY"
    open "$URL"
  }

When used your default browser should open up with this screen:

View of the create a PR screen

© 2024