$ErrorActionPreference = 'Stop' is not set -e, whatever the name suggests. A native command like git can exit nonzero and the script just keeps going, with the code sitting in $LASTEXITCODE. Set $PSNativeCommandUseErrorActionPreference = $true and a nonzero exit becomes an error that Stop stops on. The default is $false, which I found out the slow way.