Interview Prep/Git & GitHub/GitHub, Actions and Pull Request Issues

A "changed files" step runs `git diff --name-only ${{ github.event.before }} HEAD` and fails with `fatal: bad object 0000000000000000000000000000000000000000`.

AdvancedTroubleshootingGitHub, Actions and Pull Request Issues
Answer

Likely causes → On the first push of a new branch, github.event.before is all zeros. After a force-push it is a SHA that no longer exists in the remote, and with a shallow clone the old commit is never present locally either (fatal: bad object <sha>).

Diagnose → echo "${{ github.event.before }}" and git rev-parse --is-shallow-repository.

Fix → Handle these cases explicitly:

BEFORE="${{ github.event.before }}"
if [ "$BEFORE" = "0000000000000000000000000000000000000000" ] || ! git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
  git fetch --no-tags origin main
  BEFORE=$(git merge-base origin/main HEAD)
fi
git diff --name-only "$BEFORE" HEAD

Use fetch-depth: 0 (or enough depth) so the base commit exists.

Prevent → Prefer comparing against the merge base with the default branch over event.before.

All Git & GitHub questions Roadmap: Git & GitHub

More on GitHub, Actions and Pull Request Issues