branches: GET /repos/{owner}/{repo}/branches/master 301-redirects to the current default branch; response semantics undocumented
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- github, openapi
- Domain
- api, documentation
Research direction
Start with the REST reference for GET /repos/{owner}/{repo}/branches/{branch} and compare its 301 response with the 2020 changelog and 2023-02-07 update. Document when the redirect occurs and that Location may name a different branch, or reconcile the endpoint with the published behavior; the observations and suggested wording in this issue define done.
Written by the indexing model from the issue text.
Description
Routed here from https://github.com/github/docs/issues/45642 — thanks to @subatoi for pointing at the right repo.
The API behaviour half is also open as a community discussion: https://github.com/orgs/community/discussions/206039
What the docs say vs what the API does
The REST reference for branches lists 301 Moved permanently among the responses for GET /repos/{owner}/{repo}/branches/{branch}, but does not say when that redirect fires, or that Location may name a different branch than the one requested.
The changelog entry Links to deleted branches now redirect to the default branch (2020-07-17) announced this redirect, and an update appended to that same entry on 2023-02-07 withdraws it:
This behavior conflicted with other GitHub URL patterns, so we removed it. GitHub does redirect renamed branches, but not deleted branches.
That entry concerns web links. The REST API today still redirects, and it redirects to branches that no rename plausibly relates to master.
Measured 2026-08-28, redirect-following disabled
symfony/symfony /branches/master -> 301 Location=.../branches/8.2
scala/scala /branches/master -> 301 Location=.../branches/2.13.x
twitter/finagle /branches/master -> 301 Location=.../branches/develop
pytorch/pytorch /branches/master -> 301 Location=.../branches/main
kubernetes/kubernetes /branches/master -> 200 name=master (no redirect)
symfony/symfony /branches/nope-xyz -> 404
Nobody renamed master to 8.2, 2.13.x, or develop. Those are simply the current default branches.
Boundary
| question | result |
|---|---|
| Other retired conventional names? | No. trunk, develop, dev all 404 where absent — including trunk on nodejs/node. Only the literal master redirects. |
Repos that plausibly never had a master? |
Yes, still fires. anthropics/claude-code (created 2025-02-22) and astral-sh/uv (created 2023-10-02) each 301 to main. |
Does Location track the current default? |
Yes, in every repo measured. |
| Controls | apache/subversion /branches/trunk → 200 (it is the default); twitter/finagle /branches/develop → 200 (it exists); a live master returns itself; a never-existing ref 404s. |
I am not claiming to know the cause — GitHub does not expose deleted-branch history, so "never had a master" is inference from a creation date, not a measurement.
Why this is worth documenting
Every HTTP client that follows redirects by default (urllib, requests, curl -L, most SDKs) turns the 301 into a transparent 200 describing a branch the caller never asked for. The failure mode is a successful read of the wrong resource — no error, no warning.
Any tool resolving a historical branch name is exposed. A pull request records its base ref as it was at the time, so old PRs name branches that are now gone:
b = get(f"/repos/{repo}/branches/{pr['base']['ref']}") # 200. Looks fine.
cmp = get(f"/repos/{repo}/compare/{b['name']}...{head}") # answers about the wrong branch
In my own use — comparing a PR's head against the branch it targeted — this silently defeated a fix that existed specifically to stop comparing against the default branch. Across a sample of 379 pull requests in 108 repositories, 46 of 48 resolution failures were this redirect.
The guard callers need is name equality, not HTTP status:
if b["name"] != ref: # the requested ref is gone; this is a different branch
Suggested doc change
Any one of these would remove the surprise:
- Document on the branches endpoint when the
301fires, and thatLocationmay name a different branch. - Reconcile with the 2023-02-07 withdrawal, which currently reads as though this redirect no longer exists.
- If the behaviour is intended to be renamed-branches-only, the observations above suggest it is broader than that.
Documentation alone would be enough. The behaviour is defensible; the contradiction with a published withdrawal is what makes it cost people time.
- Dominant language
- No language data
- Stars
- 1.6k
- Forks
- 342
- Avg merge
- 3h 33m
- Merged PRs (30d)
- 51
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from github/rest-api-description
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
github/rest-api-description#7201 ·
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
github/rest-api-description#7163 ·
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
github/rest-api-description#7162 ·
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
github/rest-api-description#7135 ·
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
github/rest-api-description#7111 · 1 comment ·
All issues in github/rest-api-description
Similar issues
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100