Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

bash

silent

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 [email protected]: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?

like image 387
offthegrass Avatar asked May 21 '15 16:05

offthegrass


1 Answers

Two ways:

git clone [email protected]:username/repo directory > /dev/null 2>&1 - older bash

and:

git clone [email protected]: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".

like image 113
Paul Avatar answered Nov 08 '22 13:11

Paul