I have this batch file (GitRepoUpdate.bat) for running git pull command with FOR loop in the GitDev directory using Command Prompt.
@ECHO OFF
:: This batch runs ' git pull ' command for all repos in C:/GitDev folder.
title Git Pull Batch
ECHO Running Git pull in every folder in GitDev
FOR /D %G in (C:\GitDev\*) Do cd %G & git pull & cd ..
ECHO Batch finished its job.
PAUSE
I saved it as a .bat file and when I try to run it (even as an Administrator) it just opens and closes instantly.
Yet, when I delete the code part of the batch:
FOR /D %G in (C:\GitDev\*) Do cd %G & call git pull & cd ..
it opens correctly and shows:
Running Git pull in every folder in GitDev
Batch finished its job.
Press any key to continue . . .
It may be me not knowing how it works but I guess the PAUSE at the end should stop the command prompt from closing…
Any ideas?
EDIT:
I forgot to add that if I paste this line:
FOR /D %G in (C:\GitDev\*) Do cd %G & git pull & cd ..
to the Command Prompt (at any location) it works properly and does its job.
>Solution :
Batch files need an extra % on variables for reasons I can’t recall.
Try FOR /D %%G in (C:\GitDev\*) Do cd %%G & call git pull & cd .. instead.