Deleted branch name starting with `master` is redirected to a garbled URL (bug)

Today, we renamed the default branch of https://github.com/correctcomputation/checkedc-clang from master-post-microsoft to main (see the bottom for the backstory). This caused existing “view” links to master-post-microsoft to break, but not in the way I expected. For example, this link (which appeared in one of our documents outside GitHub):

https://github.com/correctcomputation/checkedc-clang/blob/master-post-microsoft/clang/docs/checkedc/Setup-and-Build.md

now redirects to:

https://github.com/correctcomputation/checkedc-clang/blob/main/-post-microsoft/clang/docs/checkedc/Setup-and-Build.md

Both pages would be 404s, but the main/-post-microsoft in the second URL makes no sense. It looks like GitHub intended to redirect the master branch to main, but it also matches master at the beginning of a longer branch name and replaces it with main/, leaving the rest of the branch name as a path component. I feel pretty confident in saying this is a bug.

For comparison, a link to a deleted branch that doesn’t begin with master shows a 404 without being redirected:

https://github.com/correctcomputation/checkedc-clang/tree/optimize_graph_insert

The renaming page states:

We’ve updated GitHub.com to redirect links that contain the deleted branch name such as master to the corresponding link in the repository’s new default branch.

According to that documentation, the expected behavior would be to redirect both links to the same paths in our new default branch (main), respectively:

  • https://github.com/correctcomputation/checkedc-clang/blob/main/clang/docs/checkedc/Setup-and-Build.md
  • https://github.com/correctcomputation/checkedc-clang/tree/main

It’s possible that GitHub intentionally changed the design to apply the redirection only to a deleted branch named master and neglected to update the documentation. If so, then the behavior in the second example is as intended and only the documentation needs to be updated to match it, but the behavior in the first example is still a bug: the URL should be left to show a 404 as is rather than being redirected to a garbled URL.

I’m submitting this report here according to these instructions. I didn’t find any previous discussion of the issue in a few web searches. (I had to prevent several URLs in this post from being formatted as links to work around the forum’s new user restriction, “Sorry, new users can only put 2 links in a post”, and to bypass the automatic edit “Github link was replaced with a permanent link”, both of which you can see are counterproductive in this case.)

For anyone curious: The awkward master-post-microsoft name arose after I foolishly submitted a PR from our master to another repository, not realizing that (1) we’d want to make more commits on our master before this PR was merged without them becoming part of the PR and (2) I could not change the source branch name after creating the PR (a GitHub limitation that could probably be the subject of a separate enhancement request).

1 Like