Silence git (no errors, no output, don't speak a word)
I am 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 to use a different source. I don't need to tell the user that this is happening. The user doesn't have to know that 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?
source to share
Two ways:
git clone git@gitlab.com:username/repo directory > /dev/null 2>&1
- older than bash
and
git clone git@gitlab.com:username/repo directory &> /dev/null
- newer bash (above version 4 according to the link below)
Read more on Redirecting I / O in bash . Basically, you are redirecting here to both stdout
, and stderr
to /dev/null
that "nowhere".
source to share