Redirect blob/tree urls when a branch is renamed

If we want to rename our default branch from master to main then we need to make sure every link that pointed to master is updated as well.

This is sometimes not possible if the published document is locked. I realize that we just “shouldn’t have linked to a branch because the file gets removed” but for evergreen files such as “README” or “CONTRIBUTING” this would be a bit unfortunate.

If GitHub would redirect links to tree and blob (e.g. for renamed branches we wouldn’t have this issue.

1 Like

Hey eps1lon! :wave:

Thanks for this feedback! We’re always working to improve GitHub and the GitHub Support Community, and we consider every suggestion we receive.

Would you mind submitting this through our official product feedback form so that our product team can track your request?

What should I fill in under “What part of GitHub is your feedback about?”?

I think this would come under “other”! That means it goes to the main Product Team, rather than one of the more specialized sub=teams…

1 Like

A git repository doesn’t know how branches have been renamed, so I don’t know how this would work. I did suggest a few weeks ago that there should be a synthetic branch name such as _default that would resolve to whatever a repository’s default branch is. However, this may be premature optimization. How often are we going to paradigmatically change the default branch name? After some discussion at my workplace, main is the new default.

Perhaps the suggestion should be that if a URL references a branch that does not exist, it should be redirected to the current default branch with an advisory.

A git repository doesn’t know how branches have been renamed

Sure, github can know it though if it allows branch renaming within its UI.

A magic name for default branches wouldn’t help in our case since we go through cycles where main development happens on main or alpha branches. Having docs link to alpha branches would not be ideal.

One of my work colleagues discovered that you can use HEAD to reference through the project’s default branch.

Thanks! That works for some use cases. If HEAD always points to a “stable” branch or at least candidates for stable then all is fine. But sometimes we go through cycles where development happens on an unstable branch I wouldn’t want links to point to unstable work.

Adding redirects for branch renames comes down to “don’t break the web”

GitHub now redirects broken view links to the default branch.