Bug Fix·Pushed May 1, 2026·S
Default branch fallback added to prevent checkout crashes
The default branch lookup in GitHub Actions workflows now gracefully handles missing origin/HEAD references, falling back to HEAD instead of crashing on fresh checkouts.
When GitHub Actions runs a fresh checkout of a repository, the origin/HEAD symbolic reference isn't always set immediately. This caused the default branch lookup to fail mid-workflow. Now the function catches that failure and returns HEAD as a fallback, ensuring workflows complete successfully even in this scenario. The fix also silences stderr during the lookup to keep action logs clean.
Technical description
The [[code ref=1]]defaultBranch[[/code]] function in [[code]]action/src/git.ts[[/code]] previously ran a [[code]]git symbolic-ref[[/code]] command against the origin/HEAD reference. This command fails when a repository is freshly checked out via [[code]]actions/checkout[[/code]] and origin/HEAD hasn't been initialized yet. The change wraps this command in a try-catch block. On failure, the function returns the string [[code]]'HEAD'[[/code]] instead of propagating the error. Additionally, [[code]]stdio: ['ignore', 'pipe', 'ignore'][[/code]] is added to suppress stderr output during the symbolic-ref call, preventing error messages from cluttering action logs when the command fails.
````typescript
file=action/src/git.ts
export function defaultBranch(repoDir: string): string {
try {
return execSync('git symbolic-ref --short refs/remotes/origin/HEAD', {
cwd: repoDir,
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore'],
})
.trim()
.replace(/^origin\//, '');
} catch {
return 'HEAD';
}
}
````
Files at a Glance:
- [[code]]action/src/git.ts[[/code]]: Added try-catch fallback in [[code]]defaultBranch[[/code]] function for missing origin/HEAD references
Categories
- Bug Fix (85%) — The primary purpose is fixing a crash that occurs when origin/HEAD is missing after a fresh GitHub Actions checkout. A try-catch fallback is added to handle this case gracefully.
- Maintenance (15%) — The change also improves error handling by redirecting stderr to ignore, keeping output clean when the command fails.