-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add a new --push flag to the pr create command #12140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
|
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. |
There was a problem hiding this 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
PushFirstboolean field toCreateOptionsstruct - Registered
--pushflag 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.
| 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 | ||
| } | ||
| } |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
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")
}There was a problem hiding this comment.
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
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.