Skip to content

pr create: flag to push local branch to remote without prompting #8152

@arturhoo

Description

@arturhoo

My workflow with private repositories usually consists of:

  1. Create a new branch locally
  2. Modify code and create commits
  3. Create a PR in the private repository using gh repo create --fill

The vast majority of times, the PR will be created in the base repository as defined by

func (r *ResolvedRemotes) BaseRepo(io *iostreams.IOStreams) (ghrepo.Interface, error) {

In other words, I'm pushing my local branch to the origin remote (the central, private repository) as part of the PR creation flow.

This is currently done through an interactive prompt, where the base repository is presented as the first option - I've created the muscle memory of just pressing <enter> right after running gh pr create every time.

Proposed solution

Implement a new flag that is functionally equivalent of selecting the first option presented in the interactive prompt of pr create when the local branch hasn't been pushed to a remote.

Users who primarily work on private repositories will usually only have a single push target, making the interactive prompt at each PR make less sense.

Alternatives

I can always run git push -u origin HEAD before calling gh pr create. Alternatively, an alias based approach was proposed in #1718 (comment) - gh alias set --shell cpr 'git push -u origin HEAD && gh pr create $*'.

Additional context

This has been previously discussed in:

Creating a new issue at the request of @andyfeller on #8146

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIgh-prrelating to the gh pr command

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions