Disable warning about detached HEAD

Zitrax picture Zitrax · Apr 22, 2016 · Viewed 12.4k times · Source

In git if you checkout a commit directly you get a big fat warning starting with:

"You are in 'detached HEAD' state. You can look around ..."

It's fine - I intend to be in detached HEAD state. However I am using this in a script and I don't want this warning in the output logs but I do want the normal output.

My "ugly" workaround now is to run the same command twice, first with -q to hide the warning, and one more time to get the normal output: HEAD is now at deadbeef... Message since the warning is only printed once.

Can the warning be disabled so I can avoid workarounds or parsing the output ?

Answer

Matthieu Napoli picture Matthieu Napoli · Aug 12, 2017

Shamelessly copying mjs's comment to post it as an answer on its own:

git -c advice.detachedHead=false checkout <refspec>

The -c advice.detachedHead=false parameter will allow you to suppress the warning without having to change the global config. It will only apply to the executed command. Here's the list of all advises that can be suppressed.