Skip to content

Instantly share code, notes, and snippets.

@dannf
Last active March 11, 2025 14:41
Show Gist options
  • Save dannf/3dd8382a67f06fd4b6d832743fc04e07 to your computer and use it in GitHub Desktop.
Save dannf/3dd8382a67f06fd4b6d832743fc04e07 to your computer and use it in GitHub Desktop.
Creating a PR non-interactively with the `gh` cli

Creating a PR non-interactively with the gh cli

This seems like it should be straightforward, but I found the documentation confusing.

gh needs to know which project you want to create a PR against. You can set this once in your repository:

gh repo set-default wolfi-dev/os

The gh command does not seem to want to push code for you without interactively prompting. So you need to this on your own:

git push my-remote

The gh command needs to know where to find that pushed code. It does so by looking at your branch's upstream setting, so you need to make sure that exists:

git branch --set-upstream-to my-remote/my-branch

Now gh has everything it needs to know, and can create a PR w/o prompting:

gh pr create -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment