Can git operate in "silent mode"?

Git

Git Problem Overview


Is it possible to execute any git command in "silent" mode? For instance, can i say "git push origin" and see nothing displayed on the screen?

I suppose i can redirect IO to /dev/null (works fine), but .. does git allow something like this naturally?

Below is a quick script that does automatic EOD commit, used when i need to catch the train and don't want to leave code on my local computer

  1 clear
  2
  3 cd
  4 cd repo/active
  5
  6 for i in *
  7 do
  8   cd $i
  9   echo "Pushing " $i
 10   git add . -A >> /dev/null 
 11   git commit -a -m "EOD automatic commit" >> /dev/null 
 12   git push origin >> /dev/null 
 13   echo
 14   cd ..
 15 done

Please let me know.

Git Solutions


Solution 1 - Git

You can use --quiet or -q, which can also be used for other Git commands:

git commit --quiet
git push --quiet

Solution 2 - Git

Using &> /dev/null at the end gives you a completely silent git command output.

git fetch origin master &> /dev/null

Solution 3 - Git

Redirecting output to /dev/null seems like a natural way of doing it to me. Although I have in the past defined a quiet_git shell function like this for use in cron jobs:

quiet_git() {
    stdout=$(tempfile)
    stderr=$(tempfile)

    if ! git "$@" </dev/null >$stdout 2>$stderr; then
        cat $stderr >&2
        rm -f $stdout $stderr
        exit 1
    fi

    rm -f $stdout $stderr
}

This will suppress stdout and stderr, unless the git command fails. It's not pretty; in fact the stdout file is ignored and it should just redirect that to /dev/null. Works, though. And then you can just do "quiet_git push" etc. later on in the script.

Solution 4 - Git

Note that even with --quiet, a git fetch (which triggers a git gc) would generate some output.
That is because of the git gc part of the git fetch.

Not anymore, starting git 2.1.1 (Sept 2014): see commit 6fceed3bea59d747c160972c67663e8b8c281229 from Nguyễn Thái Ngọc Duy (pclouds)

fetch: silence git-gc if --quiet is given

builtin/fetch.c:

argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
if (verbosity < 0)
argv_array_push(&argv_gc_auto, "--quiet");
run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJames RaitsevView Question on Stackoverflow
Solution 1 - GitZoe EdwardsView Answer on Stackoverflow
Solution 2 - GitHans KristianView Answer on Stackoverflow
Solution 3 - GitaraqnidView Answer on Stackoverflow
Solution 4 - GitVonCView Answer on Stackoverflow