til
One alias to view or create a GitHub PR
A simple shell alias that saves a surprising amount of context switching.
A simple shell alias that saves a surprising amount of context switching:
alias ghpr="gh pr view --web 2>/dev/null || gh pr create --web"
How it works
gh pr view --webtries to open the PR for the current branch in your browser- If no PR exists, it exits non-zero (stderr suppressed with
2>/dev/null) - The
||fallback then runsgh pr create --webto open the create PR page instead
Why it’s useful
Without this, the workflow is:
- Run
gh pr view --web - See the error “no pull requests found”
- Run
gh pr create --web
With this alias, you just type ghpr and you’ll end up in the right place regardless of whether a PR already exists or not.