Skip to content

fix(git): pin auto-init default branch to main#472

Merged
melvincarvalho merged 1 commit into
gh-pagesfrom
issue-471-pin-default-branch
May 16, 2026
Merged

fix(git): pin auto-init default branch to main#472
melvincarvalho merged 1 commit into
gh-pagesfrom
issue-471-pin-default-branch

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Fixes #471.

What

tryAutoInitRepo now calls git init -b main <path> instead of bare git init <path>. The auto-init'd HEAD points at refs/heads/main regardless of the server's init.defaultBranch setting.

Why

receive.denyCurrentBranch updateInstead only extracts the working tree when the incoming push targets the branch HEAD points at. If a server has init.defaultBranch=gh-pages (e.g. an operator who lives in GitHub Pages land), then git push pod HEAD:main succeeds at the protocol layer — the ref is created — but no files appear on disk and the path returns 404 for every resource. Silent failure that's invisible at the protocol layer.

Bit us during end-to-end install testing of solid-apps (chrome, vellum, etc.) on jspod. Workaround was "know the server's init.defaultBranch and push to that name" — not acceptable for a public-facing onboarding flow.

Behavior change

Server init.defaultBranch Before After
main works works
master push HEAD:master works; HEAD:main silently fails push HEAD:main works
gh-pages only HEAD:gh-pages works push HEAD:main works
unset / other depends on local git push HEAD:main works

Users pushing to a non-main branch name will continue to see refs accepted but the working tree not extracted (same as today, just now consistent across deployments). The wrapper docs (jspod) will note "push to main".

Optional follow-up

A --git-default-branch <name> server flag (defaulting to main) would let operators override without an explicit per-request mechanism. Not needed for this fix; can file separately if anyone asks.

Test plan

  • Added pins the initial branch to \main` regardless of server configintest/git-auto-init.test.js— reads.git/HEADafter auto-init and assertsref: refs/heads/main`
  • All 7 tests in test/git-auto-init.test.js pass locally on this branch
  • CI green

…teInstead

`git init` (no `-b`) honours the server's `init.defaultBranch`, which
on a server configured for e.g. `gh-pages` makes pushes to `main`
silently fail to extract the working tree (the ref updates but
`receive.denyCurrentBranch updateInstead` only fires when the push
matches the branch HEAD points at).

Pass `-b main` explicitly so the auto-init'd HEAD is deterministic
regardless of server config. `git push pod HEAD:main` then works on
every deployment.

Adds a test reading `.git/HEAD` and asserting `ref: refs/heads/main`.

Fixes #471
@melvincarvalho
melvincarvalho merged commit aa93d26 into gh-pages May 16, 2026
1 check passed
@melvincarvalho
melvincarvalho deleted the issue-471-pin-default-branch branch May 16, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git auto-init: pin the default branch name (git init -b main) so updateInstead reliably extracts working tree

1 participant