Reputation: 1376
I'm using git in the terminal and know most of the commands I need by heart. Therefore I would like to suppress the "help hints" in the output, i.e. all the text in parenthesis starting with (use "git ...
) to make the output less verbose.
I know of the flags --short
and --porcelain
, but then the output is less readable on a quick glance IMHO.
Is there a way to keep the default formatting of the output but without the help text?
Example:
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Changes not staged for commit:
modified: file1.txt
modified: file2.txt
Untracked files:
untracked_file.txt
no changes added to commit
... instead of ...
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: file1.txt
modified: file2.txt
Untracked files:
(use "git add ..." to include in what will be committed)
untracked_file.txt
no changes added to commit (use "git add" and/or "git commit -a")
Upvotes: 16
Views: 7903
Reputation: 1323753
TLDR; use in scripts the --no-advice
Git option (Git 2.46+, Q3 2024), or export GIT_ADVICE=0
.
Example: git --no-advice status
.
The git config --global advice.* false
mentioned in the other answers gain a new feature with Git 2.44 (Q1 2024), batch 12: all conditional "advice
" messages show how to turn them off, which becomes repetitive.
Setting advice.*
configuration explicitly on now omits the instruction part.
See commit d919965 (15 Jan 2024) by Rubén Justo (rjusto
).
See commit 8cf646f (16 Jan 2024) by Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
-- in commit e14c0ab, 30 Jan 2024)
advice
: allow disabling the automatic hint inadvise_if_enabled()
Signed-off-by: Rubén Justo
Using
advise_if_enabled()
to display an advice will automatically include instructions on how to disable the advice, alongside the main advice:hint: use --reapply-cherry-picks to include skipped commits hint: Disable this message with "git config advice.skippedCherryPicks false"
To do so, we provide a knob which can be used to disable the advice.
But also to tell us the opposite: to show the advice.
Let's not include the deactivation instructions for an advice if the user explicitly sets its visibility.
git config
now includes in its man page:
When left unconfigured, Git will give the message alongside instructions on how to squelch it.
You can tell Git that you do not need the help message by setting these to 'false'.
With Git 2.45 (Q2 2024), batch 16, the "hint:
" messages given by the advice mechanism, when given a message with a blank line, left a line with trailing whitespace, which has been cleansed.
In your case, the above messages will now be:
hint:use --reapply-cherry-picks to include skipped commits hint:Disable this message with "git config advice.skippedCherryPicks false"
See commit 2d8cf94 (29 Mar 2024) by Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
-- in commit 39b2c6f, 09 Apr 2024)
advice
: omit trailing whitespace
Git tools all consistently encourage users to avoid whitespaces at the end of line by giving them features like "
git diff --check
"(man) andgit am --whitespace=fix".
(man)
Make sure that the advice messages we give users avoid trailing whitespaces.
We shouldn't be wasting vertical screen real estate by adding blank lines in advice messages that are supposed to be concise hints, but as long as we write such blank line in our "hints", we should do it right.A test that expects the current behaviour of leaving trailing whitespaces has been adjusted.
With Git 2.46 (Q3 2024), batch 5, a new global "--no-advice
" option can be used to disable all advice messages, which is meant to be used only in scripts.
See commit cbdc83f (07 May 2024) by Junio C Hamano (gitster
).
See commit b79deeb, commit 5bd8811, commit 9b715ad (03 May 2024) by James Liu (jamesliu96
).
(Merged by Junio C Hamano -- gitster
-- in commit f0e2183, 16 May 2024)
advice
: add--no-advice
global optionSigned-off-by: James Liu
Advice hints must be disabled individually by setting the relevant advice.* variables to false in the Git configuration.
For server-side and scripted usages of Git where hints can be a hindrance, it can be cumbersome to maintain configuration to ensure all advice hints are disabled in perpetuity.
This is a particular concern in tests, where new or changed hints can result in failed assertions.Add a
--no-advice
global option to disable all advice hints from being displayed.
This is independent of the toggles for individual advice hints.
Use an internal environment variable(GIT_ADVICE)
to ensure this configuration is propagated to the usage site, even if it executes in a subprocess.
git
now includes in its man page:
--no-advice
Disable all advice hints from being printed.
With Git 2.47 (Q4 2024), batch 16, the environment GIT_ADVICE
has been intentionally kept undocumented to discourage its use by interactive users.
Add documentation to help tool writers.
See commit fb2b981 (06 Sep 2024) by Derrick Stolee (derrickstolee
).
(Merged by Junio C Hamano -- gitster
-- in commit 19de221, 13 Sep 2024)
advice
: recommendGIT_ADVICE=0
for toolsCo-authored-by: Junio C Hamano
Signed-off-by: Derrick Stolee
The
GIT_ADVICE
environment variable was added implicitly in b79deeb ("advice
:add
(man)--no-advice
global option", 2024-05-03, Git v2.46.0-rc0 -- merge listed in batch #5) but was not documented.
Add documentation to show that it is an option for tools that want to disable these messages.
Make note that while the--no-advice
option exists, older Git versions will fail to parse that option.
The environment variable presents a way to change the behavior of Git versions that understand it without disrupting older versions.
git config
now includes in its man page:
that you have understood the issue and no longer need a specific help message by setting the corresponding variable to
false
.As they are intended to help human users, these messages are output to the standard error. When tools that run Git as a subprocess find them disruptive, they can set
GIT_ADVICE=0
in the environment to squelch all advice messages.
git
now includes in its man page:
GIT_ADVICE
If set to
0
, then disable all advice messages.These messages are intended to provide hints to human users that may help them get out of problematic situations or take advantage of new features.
Users can disable individual messages using the
advice.*
config keys.
These messages may be disruptive to tools that execute Git processes, so this variable is available to disable the messages. (The--no-advice
global option is also available, but old Git versions may fail when this option is not understood. The environment variable will be ignored by Git versions that do not understand it.)
With Git 2.48 (Q1 2025), rc0, the advice messages now tell the newer 'git config set
'(man) command to set the advice.token configuration variable to squelch a message.
See commit 6c397d0 (05 Dec 2024) by Bence Ferdinandy (ferdinandyb
).
(Merged by Junio C Hamano -- gitster
-- in commit e6663b9, 15 Dec 2024)
advice
: suggest using subcommand "git config set"Signed-off-by: Bence Ferdinandy
The advice message currently suggests using "
git config
"(man) advice... to disable advice messages, but since00bbdde (
builtin/config
: introduce , 2024-05-06, Git v2.46.0-rc0 -- merge listed in batch #4) (builtin/config: introduce "set" subcommand, 2024-05-06)we have the "
set
" subcommand for config.
Since using the subcommand is more in-line with the modern interface, any advice should be promoting its usage.
Change the disable advice message to use the subcommand instead.
Change all uses of "git config
" advice in the tests to use the subcommand.
So:
Disable this message with git config set advice.%s false
Upvotes: 4
Reputation: 282845
Combining a few answers here into something copy-and-pastable:
git help --config | grep -P '^advice\.' | xargs -t -i% git config --global % false
Upvotes: 0
Reputation: 2673
You can also add something like the following snippet into your ~/.gitconfig
:
[advice]
statusHints = false
pushUpdateRejected = false
pushNonFFCurrent = false
pushNonFFMatching = false
pushAlreadyExists = false
pushFetchFirst = false
pushNeedsForce = false
statusHints = false
statusUoption = false
commitBeforeMerge = false
resolveConflict = false
implicitIdentity = false
detachedHead = false
amWorkDir = false
rmHints = false
Upvotes: 1
Reputation: 1547
Git offered enabling/disabling advice by using the 'advice.*' key in the configuration. See git help config
for more information or the online manpage. The following 14 variables exist:
advice.pushUpdateRejected
advice.pushNonFFCurrent
advice.pushNonFFMatching
advice.pushAlreadyExists
advice.pushFetchFirst
advice.pushNeedsForce
advice.statusHints
advice.statusUoption
advice.commitBeforeMerge
advice.resolveConflict
advice.implicitIdentity
advice.detachedHead
advice.amWorkDir
advice.rmHints
You can set them with git config --global advice.*
. For example git config --global advice.statusHints false
. Note that I have not seen a way to disable all the same time.
Upvotes: 18
Reputation: 2990
@somnium created a list, here is a way to disable all advice globally:
man git-config | sed '0,/advice.*/d;/^ \w/,$d' | grep '^ \w\+$' | xargs -i% git config --global --add advice.% false
This is kinda brittle due to reliance on the man-page format, but should work reliably.
Upvotes: 0