2

I am making a small batch file to pull from git. I use the following:

call git pull origin master

But would like the rest of the batch file to stop running when the response of the command is Already up-to-date.

How do I do that?

Alvin Bakker
  • 1,456
  • 21
  • 40

1 Answers1

4

Pipe it to findstr then check the error level

git pull | findstr /C:"Already up-to-date"

IF %errorlevel%==0 GOTO:EOF

echo Continuing ....

To explain the relationship of findstr and errorlevel http://ss64.com/nt/findstr.html says:

FINDSTR will set %ERRORLEVEL% as follows:

0 (False) a match is found in at least one line of at least one file.
1 (True) if a match is not found in any line of any file, (or if the file is not found at all).
2 Wrong syntax 
An invalid switch will only print an error message in error stream.
Chris Moutray
  • 18,029
  • 7
  • 45
  • 66
FloatingKiwi
  • 4,408
  • 1
  • 17
  • 41