Resolve the canonical drupal.org remote when switching to a non-local branch - #37
Merged
Conversation
This was referenced Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Issue
How This PR Solves The Issue
A new
switch_to_branchhelper, used by both the core and the contrib module path, replaces the baregit switch. When the branch is already local it switches as before, and otherwise it resolves a remote itself and switches with--track, which is what removes the ambiguity.The resolution order:
git switch <branch>, since--trackwould fail there.project/<name>(drupalfor core, the module name for contrib), which is what tells the canonical repository apart from issue forks.checkout.defaultRemote, if the user set it.origin, if it has the branch.And when git doesn't know the branch yet, the command says so instead of falling over on
fatal: invalid reference: 11.x:When several remotes do have it and none of them looks canonical, it lists them and shows how to pick:
Nothing is written to git config, so this also covers existing checkouts, people whose canonical remote is named
upstreamordrupal, and anyone whoseoriginis a personal fork, since a fork remote can't win the URL step whatever it is called. The README's core branch switching section now mentions the behaviour.Manual Testing Instructions
Automated Testing Overview
Covered by a fake-fork case in the module management test.