git / zero sha
A zero SHA is a commit hash made of only 0 characters.
Git uses it as a null object ID for refs that point nowhere.
For SHA-1 repos, it is 40 zeros:
0000000000000000000000000000000000000000
For SHA-256 repos, it is 64 zeros:
0000000000000000000000000000000000000000000000000000000000000000
Where it appears
You usually see zero SHAs in push events and hooks,
not in normal git log output.
In push semantics:
- branch creation:
beforeis zero,afteris the first commit - branch deletion:
beforeis the old commit,afteris zero
Webhook payloads may also send before as an empty string
on branch creation.
Treating empty and zero as equivalent makes handlers resilient.
Practical check in Go
func isZeroSHA(sha string) bool {
sha = strings.TrimSpace(sha)
if sha == "" {
return true
}
if len(sha) != 40 && len(sha) != 64 {
return false
}
for _, r := range sha {
if r != '0' {
return false
}
}
return true
}
Then branch your logic:
switch {
case isZeroSHA(before):
fmt.Println("branch created")
case isZeroSHA(after):
fmt.Println("branch deleted")
default:
fmt.Println("normal push")
}
Why this matters
Without a zero-SHA check, automation can misclassify branch creation and deletion events. That can trigger noisy automation and incorrect event handling.