Skip to content
Latchkey

macOS runner: "brew update ... fatal: not in a git directory" in CI

Homebrew updates by running git inside its core and tap repositories. If that directory is not a valid git repo (missing or corrupt .git), brew update aborts with "fatal: not in a git directory".

What this error means

A brew update step fails with "fatal: not in a git directory" or "fatal: detected dubious ownership in repository", and brew cannot refresh formula definitions.

Homebrew
==> Updating Homebrew...
fatal: not in a git directory
Error: Failure while executing; `git ...` exited with 128.

Common causes

Homebrew core repo lost its git metadata

A shallow or partial image, or a deleted .git, leaves the Homebrew/core checkout without the git repo brew update needs.

Git refuses the repo as dubious ownership

If the repo is owned by a different user than the one running brew, modern git blocks it with a dubious-ownership error that surfaces during update.

How to fix it

Mark the Homebrew repos as safe and refetch

  1. Add the Homebrew repo paths to git safe.directory.
  2. If git history is missing, fetch it so the repo is valid again.
  3. Re-run brew update.
Terminal
git config --global --add safe.directory "$(brew --repository)"
git -C "$(brew --repository)" fetch --unshallow || true
brew update

Skip the update when not needed

If formulae are already current for the job, set HOMEBREW_NO_AUTO_UPDATE so brew does not attempt the failing update at all.

Terminal
export HOMEBREW_NO_AUTO_UPDATE=1
brew install <formula>

How to prevent it

  • Add Homebrew repo paths to git safe.directory in CI.
  • Set HOMEBREW_NO_AUTO_UPDATE=1 when an update is unnecessary.
  • Use the runner image as shipped rather than mutating brew internals.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →