Skip to content

This notebook belongs to

Sadat Jubayer

Senior Software Engineer at Premio

If found, please return to hello@jubayer.dev

Vol. 7Seven years of building

Started
January 2020
Everyday tools
TypeScript, Vue, React, Next.js, NestJS, React Native
Education
B.Sc. CSSE, AIUB, 2020
1 min readGit

Silence hints with git --no-advice

Use Git’s global --no-advice flag to remove remediation hints from script logs while preserving command output and failure status.

A script runs Git and records stderr for a failed job. If the job already prints its own next step, turn off Git’s advice for that invocation. Git still reports the failure.

Compare two failed commands

Create a throwaway repository and ask Git to stage a file covered by its ignore rules. Run both blocks in the same shell. If your script uses set -e, run the example interactively so it can print the status after the expected failure.

work=$(mktemp -d)
cd "$work" || exit 1
git init -q
printf 'report.log\n' > .gitignore
touch report.log
git -c advice.addIgnoredFile=true add report.log
printf 'status=%s\n' "$?"

Git lists report.log as ignored, prints hints about forcing the add, and returns status 1.

Run the same add in that directory with the global flag. Put it between git and the subcommand, so Git's top-level command line parser sees it.

git --no-advice -c advice.addIgnoredFile=true add report.log
printf 'status=%s\n' "$?"

Git still lists the ignored file and the status is still 1. The hint: lines are gone.

The -c setting in both commands makes this comparison independent of the personal setting for ignored-file hints. In your script, use git --no-advice add … and handle its exit status as you would for git add. In particular, a command that writes to stderr can still have useful diagnostics there after advice is disabled.

Pick the scope for a script

The global flag applies to one call. Use it where a script knows how to handle a failure or prints its own next step. Keep the default advice for commands you run by hand, where the hint may name an option you need.

Git added the flag in 2.46. If a machine reports unknown option: --no-advice, that invocation stopped before running the subcommand. For a script that supports older Git, omit the flag there or use a command-scoped -c advice.addIgnoredFile=false when the ignored-file hint is the one you need to suppress.