Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a shell script that pulls my repository from git. Normally, it receives the credentials and the pull works just fine.

My question is what happens if the credentials are wrong and I get an authentication failure. How can I catch this error and stop the shell script?

share|improve this question

All commands return a single-byte value (from 0 through 255) after they have completed executing. Usually a 0 return value indicates success and non-0 indicates some sort of problem. Various shells have constructs that check the 0-ness of the return value and can act upon it.

if git ...
  echo "git succeeded"

if ! git ...
  echo "git failed"

git ... || echo "git failed"
git ... && echo "git succeeded"
share|improve this answer
Hi - thanks. What you wrote is working well when I execute the script form command line. However, I execute the script by using php which in this scenario I don't get the response from the git pull command. Any idea? – Nysd Sbar Oct 24 '12 at 12:23
I'm unclear on what you're trying to do. Are you trying to execute the script (or the git pull) from a PHP web page or a PHP-based command-line script? Do you get ANY output? Are there any errors? Can you show us exactly how you're calling the shell script using PHP? If this is in a PHP script, a code snippet will suffice. If you're using the php CLI, the command line should do it. Also note there may be a MUCH better way to do what you're trying to do so you might want to consider filling in the details a bit. – Jay Allen Oct 30 '12 at 6:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.