Skip to content

Conversation

@TheoBrigitte
Copy link

This PR introduces a new --push flag to the pr create command, allowing users to directly push their branches to the remote repository when creating a pull request without having to select the push option interactively.

@TheoBrigitte TheoBrigitte requested a review from a team as a code owner November 11, 2025 22:22
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Nov 11, 2025
@cliAutomation
Copy link
Collaborator

Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a --push flag to the gh pr create command to automatically push the current branch to the first available repository, bypassing the interactive prompt that normally asks "Where should we push the branch?"

Key changes:

  • Added PushFirst boolean field to CreateOptions struct
  • Registered --push flag in command setup
  • Modified push destination selection logic to skip prompting when flag is set

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +944 to 951
selectedOption := 0
if !opts.PushFirst {
// Prompt the user to select a repo to push to when push flag is not set.
selectedOption, err = opts.Prompter.Select(fmt.Sprintf("Where should we push the '%s' branch?", currentBranch), "", pushOptions)
if err != nil {
return nil, err
}
}
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When --push is set and there are no pushable repositories available (e.g., len(pushableRepos) == 0), selectedOption defaults to 0, which may select "Create a fork" instead of a repository. This behavior is inconsistent with the flag's description "Push the current branch to the first available repository."

Consider adding validation to ensure at least one pushable repository exists when using --push, or clarify the behavior when no repositories are available. For example:

selectedOption := 0
if !opts.PushFirst {
    // Prompt the user to select a repo to push to when push flag is not set.
    selectedOption, err = opts.Prompter.Select(fmt.Sprintf("Where should we push the '%s' branch?", currentBranch), "", pushOptions)
    if err != nil {
        return nil, err
    }
} else if len(pushableRepos) == 0 {
    return nil, fmt.Errorf("no pushable repositories found; cannot use --push flag")
}

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for len(pushableRepos) == 0) is already present on line 917

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants