it works with me with '$?'
$ git push origin master
Username for 'https://github.com': sld,sldk
Password for 'https://sld,[email protected]':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/KamelHacene/configeuh.git/'
$ echo $?
128
If the command has succeded, $? should return 0.
Just catch it in a variable (like 'var=$?') and you'll be good to go.
To catch the error message, just redirect your error output like this (stderr to file):
$ git push origin master 2>plop
Username for 'https://github.com': lskdls
Password for 'https://[email protected]':
$ cat plop
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/KamelHacene/configeuh.git/'
Or this (stderr to stdout. Use a variable to catch stdout) :
$ ploop=$(git push origin master 2>&1)
Username for 'https://github.com': skjdksd
Password for 'https://[email protected]':
$ echo $ploop
remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/KamelHacene/configeuh.git/'