24

So I have a lot of repos, and sometimes I forget if some are behind on their pulls, so I was wondering if there was a way to git pull for each repo in one .bat script. I saw someone do it for Linux I believe here, but I'm on a Windows machine. Does anyone know how to do this for Windows?

5 Answers 5

33

You can make a .bat file in which you add all the repositories yourself with this

cd C:\path\to\git\repo
call git pull
cd C:\path\to\git\repo2
call git pull

Or let it run through a whole directory with git repositories

FOR /D %G in (C:\Documents\GitRepos\*) Do cd %G & call git pull & cd ..

Instead of .bat file there is a GUI client Github for windows

If you have all your repositories in there it won't be a pain to remember to sync them all.

4
  • 1
    If that is not an option try the techniques described here: addyosmani.com/blog/backing-up-a-github-account
    – eikooc
    Commented Jun 14, 2014 at 19:50
  • I used the app in the past, but I find it so clunky, at least for me, in the time that it takes for me to open the app I could've synced a couple by command line. But the link looks really useful!
    – ROODAY
    Commented Jun 15, 2014 at 23:54
  • 1
    I believe this is exactly what you are looking for: stackoverflow.com/questions/17099564/… Correct me if I'm wrong
    – eikooc
    Commented Jun 16, 2014 at 17:44
  • 1
    I have edited the answer a bit to incorporate a better answer
    – eikooc
    Commented Jun 17, 2014 at 21:34
27

Here is a PowerShell version

Get-ChildItem -Directory | foreach { Write-Host "`n■ Getting latest for $_ ↓" -ForegroundColor Green | git -C $_.FullName pull --all --recurse-submodules --verbose }
2
12

I really liked @eikooc 's answer - and wanted it to work - but it wouldn't work for me on Windows 10.

Here is my variation:

for /f %%f in ('dir /ad /b C:\Documents\GitRepos\') do cd /d C:\Documents\GitRepos\%%f & call git pull & cd ..
3

If you got Git installed with MinGW (bash) you can execute this command that works in parallel:

ls -d **/* | xargs -P10 -I{} git -C {} pull
0

I know this is old but it gave me the answer I was looking for and wanted to share what I did for my use.

In a command prompt pointing to directory with repos

for /f %f in ('dir /ad /b %cd%\') do cd /d %cd%\%f & call git pull & cd ..

Batch file (UPDATEALL.cmd) saved in directory with repos

@echo off
for /f %%f in ('dir /ad /b %cd%') do (
    cd /d %cd%\%%f
    call git pull
    cd ..
)
pause

If you want to specify the directory look at hawkeye's answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.