offthegrass offthegrass - 1 month ago 10
Git Question

Silence git (no errors, no output, don't say a word)

I'm using git to manage some custom packages. If the package is not in the first repo, I want to run a second command that tries another source. I don't need to tell the user that this is happening. The user doesn't need to know git exists.

if ! git clone git@gitlab.com:username/repo directory -q
then
#do something else
fi


git still prints a fatal error in the console even with
-q
.

So, how do I silence the little git?

Answer Source

Two ways:

git clone git@gitlab.com:username/repo directory > /dev/null 2>&1 - older bash

and:

git clone git@gitlab.com:username/repo directory &> /dev/null - newer bash (Above version 4 according to the link below)

For more details read about I/O Redirection in Bash. Essentially what you're doing here is redirect both stdout and stderr to /dev/null, which is "nowhere".