'Failed to capture the error message in linux

Failed to capture the response for the below command;

URL="https://gsdfdsfithub.com/gitexpert/testGithub.git" > /dev/null 

git ls-remote $URL -q

if [ $? -nq 0 ]; then
    echo "Failed, please provide valid url"
fi

output:

fatal: unable to access 'https://gsdfdsfithub.com/gitexpert/testGithub.git/': Received HTTP code 404 from proxy after CONNECT
128
line 4: [: -nq: binary operator expected

I tried the above code snippet but still it's catching the error. I want to suppress the error message , and have custom message as an output. like below

"Failed, please provide valid url"


Solution 1:[1]

Print stdout and stderr to /dev/null.

URL="https://gsdfdsfithub.com/gitexpert/testGithub.git" > /dev/null 

git ls-remote $URL -q >> /dev/null 2>&1

if [ $? != 0 ]; then
    echo "Failed, please provide valid url"
fi

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 过过招