-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Allow configuring default PR base branch (fixes #36412) #36425
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: main
Are you sure you want to change the base?
Conversation
|
Is there a reason why "default" branch can't be used as PR base branch? |
|
The linked issue explains it a bit - the idea is to support a setup where you have main branch, staging branch and the dev ones and while the repository main is the first one from the list, the staging is the base one for PRs. |
Yeah, changing the default branch changes more than just PR targets. Plus, when the PR UI tries to load the diff between the "default" branch and the staging branch (which your team normally PRs to), it tends to get really laggy (making the workflow of PRing the staging branch rather tedious). |
|
it's in the title - #36412 |
Hmm, totally missed that. But still don't understand the details ... in that case, why not set
What else would it affect?
If the default branch is |
Because the default branch is the repo's canonical ref, not just "the default PR target". It affects what
Clone defaults, the repository home view/default ref in the UI, and integrations/automation that implicitly use the default branch (for example links that omit a ref, docs references, or CI setups that follow the default branch unless configured otherwise). Many repos also want the default branch to represent the stable/releasable line for external consumers and casual viewers.
It avoids the PR-base mismatch, but at the cost of making an integration branch the repo's canonical branch. A common workflow keeps A configurable default PR base branch solves the actual pain point: it reduces mistakes (accidentally opening PRs against |
|
Thank you for the clarification, it makes sense. |
Thanks for taking a look, glad the motivation makes sense. Just to confirm: this is fully opt-in (per-repo default PR base branch), so there’s no behavior change unless the setting is configured. The changes mostly wire that base through the existing PR entry points (compare links / recently pushed prompt), and add a small safety guard to avoid auto-deleting the configured base branch in same-repo PR cleanup. Do you have any concerns with the current approach, or would you like any adjustments (naming/UI wording, docs, tests, or the branch-cleanup guard behavior)? |
|
If we want to add an option for pull request ,it should be in the |
Signed-off-by: Louis <116039387+tototomate123@users.noreply.github.com>
Done - moved the setting into the PR |
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 per-repository configuration for the default pull request base branch, allowing repositories to specify a different target branch for PRs instead of always using the repository's default branch. This is useful for repositories that use a branching strategy where PRs target a development branch rather than the main/master branch.
Changes:
- Added
DefaultPRBaseBranchconfiguration field to the PR settings unit with database validation - Updated PR creation links and branch compare URLs throughout templates to use the configured base branch
- Added fallback logic when comparing the configured base branch against itself
- Implemented protection against auto-deleting the configured base branch after merge for same-repo PRs
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| models/repo/pull_request_default.go | New file implementing core logic for retrieving, validating, and checking existence of the configured default PR base branch |
| models/repo/pull_request_default_test.go | Test coverage for the default PR base branch selection and validation |
| models/repo/repo_unit.go | Added DefaultPRBaseBranch field to PullRequestsConfig struct |
| models/repo/repo.go | Updated ComposeBranchCompareURL to accept context and use the configured base branch |
| models/git/branch.go | Updated recently pushed branches to use ComposeBranchCompareURL with context |
| modules/structs/repo.go | Added DefaultPRBaseBranch to API Repository struct |
| services/repository/branch.go | Added protection to prevent auto-deletion of configured base branch in same-repo PRs |
| services/forms/repo_form.go | Added DefaultPRBaseBranch form field |
| services/convert/repository.go | Populated DefaultPRBaseBranch in API responses |
| services/context/repo.go | Set DefaultPRBaseBranch in template context data, preferring base repo's configuration |
| routers/web/repo/setting/setting.go | Added validation and handling for default PR base branch setting |
| routers/web/repo/compare.go | Updated compare page to use configured base branch when none specified |
| templates/repo/view_content.tmpl | Updated PR creation link to use configured base branch |
| templates/repo/settings/options.tmpl | Added UI dropdown for selecting default PR base branch |
| templates/repo/issue/list.tmpl | Updated new PR and compare buttons to use configured base branch |
| templates/repo/branch/list.tmpl | Updated branch compare links with fallback logic when branch matches configured base |
| templates/swagger/v1_json.tmpl | Added API documentation for default_pr_base_branch field |
| options/locale/locale_en-US.json | Added localization strings for the new setting |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
routers/web/repo/compare.go
Outdated
|
|
||
| // 4 get base and head refs | ||
| baseRefName := util.IfZero(compareReq.BaseOriRef, baseRepo.DefaultBranch) | ||
| baseRefName := util.IfZero(compareReq.BaseOriRef, baseRepo.GetDefaultPRBaseBranch(ctx)) |
Copilot
AI
Jan 23, 2026
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 API endpoint for comparing branches (routers/api/v1/repo/pull.go) also uses a default base branch when none is specified, but it's not updated to use the configured default PR base branch. For consistency, consider whether the API compare endpoint should also respect the configured default PR base branch setting when no base branch is explicitly provided in the request.
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 API compare handler intentionally defaults to DefaultBranch. Keeping it as-is avoids changing API semantics; opinions welcome.
| return nil | ||
| } | ||
|
|
||
| func isBranchNameExists(ctx context.Context, repoID int64, branchName string) (bool, error) { |
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.
Aren't there some similar functions?
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.
There's git_model.IsBranchExist, but importing models/git from models/repo creates an import cycle. I kept a small local helper here to avoid that.
|
Following up on the Copilot API compare comment: The configurable default PR base branch is currently treated as a UI / workflow concern (PR creation, compare links, prompts), and only applies when explicitly opening PRs, not when calling the compare API without a base. Before changing anything there, I wanted to ask: Happy to adjust either way, but wanted alignment before touching API defaults. The PR should otherwise be ready for another review round. |
|
Small remark regarding naming: I would rename
I would say all APIs that previously used |
…re endpoint to default target branch
|
Thanks! I've renamed |

Summary
This adds a per-repository default PR base branch and wires it through PR entry points. It updates compare links and recently pushed branch prompts to respect the configured base branch, and prevents auto-merge cleanup from deleting the configured base branch on same-repo PRs.
Behavior changes
Testing
Not run (local UI verification only).
Reviewer question: I added a guard in
services/repository/branch.go(DeleteBranchAfterMerge flow) to avoid auto-deleting the configured default PR base branch for same-repo PRs. Is that desired, or is branch protection expected to cover this?