Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quickly check if a git pull command is successful?

I wrote a bash script to loop through all git folders and do a git pull. The issue is there are a lot of folders, and the git pull command generates a lot of logs for each of them, so that I have to skim through the logs and check if any of them had failures (e.g: some might need a git reset prior to the pull) Is there a way to get kind of "success" or "failure" state of git pull result, then it'd be more concise in the logs, and I can just focus on those that failed and treat them separately.

like image 835
Duc Tran Avatar asked Jan 03 '23 17:01

Duc Tran


1 Answers

You can check if git commands were succesful or not.

After a failed git pull, the exit status would be non-zero, you can check it like this in a shell script :

if /usr/bin/git pull; then
    echo "OK"
else
    echo "Not Ok"
fi
like image 120
Nicolas L Avatar answered Jan 05 '23 10:01

Nicolas L