Run git pull out all windows command promt subdirectories

How can I update multiple git repositories from my shared parent directory without cd'ing to each root repo directory in Windows 7?

I have the following which are separate git repositories (and not submodules):

c:\projects\repos\repo1
c:\projects\repos\repo2
c:\projects\repos\repo3

On linux, I can use this bash script

find ~/projects/repos/ -type d -name .git \
| xargs -n 1 dirname \
| sort \
| while read line; do echo $line && cd $line && git pull origin $1 && echo ; done
+4
source share
3 answers

Windows Batch Solution:

if you want to use this in a .bat script use this:

for /D %%G in ("*") do (echo %%G) && (cd %%G) && (git pull origin) && (cd ..)

if it's just in the console:

for /D %G in ("*") do (echo %G) && (cd %G) && (git pull origin) && (cd ..)
+6
source

A cleaner and better way to do this is with the usual console command:

FOR /D %a IN (c:\projects\repos\*) do git -C %~fa pull

or in a .bat file

FOR /D %%a IN (c:\projects\repos\*) do git -C %%~fa pull
PAUSE

Or even a .bat file in the project directory

FOR /D %%a IN (.\repos\*) do git -C %%~fa pull
PAUSE
+5

PowerShell script:

$dirs = Get-ChildItem -Path . | ?{ $_.PSIsContainer }
$back = pwd
foreach ($dir in $dirs)
{
    cd $dir.FullName
    echo $dir.FullName
    git pull origin
}   
cd $back.Path
+4

All Articles