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?

Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
ROODAY
  • 756
  • 1
  • 6
  • 23

4 Answers4

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.

eikooc
  • 2,363
  • 28
  • 37
  • 1
    If that is not an option try the techniques described here: http://addyosmani.com/blog/backing-up-a-github-account/ – eikooc Jun 14 '14 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 Jun 15 '14 at 23:54
  • 1
    I believe this is exactly what you are looking for: http://stackoverflow.com/questions/17099564/make-a-shell-script-to-update-3-git-repos Correct me if I'm wrong – eikooc Jun 16 '14 at 17:44
  • 1
    I have edited the answer a bit to incorporate a better answer – eikooc Jun 17 '14 at 21:34
26

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 }
Ahmed Magdy
  • 5,956
  • 8
  • 43
  • 75
  • 1
    I went a bit further and created an alias in my PS profile to call `Git-Pull-All` with this sample: https://stackoverflow.com/a/29806921/228160 Full gist -> https://gist.github.com/yzraeu/12b96c409ae7da29b1a41ddccec3a0c3 – Izzy Rodriguez Apr 28 '21 at 05:27
  • For macOS bash version: https://stackoverflow.com/a/60786488/10158227 – Audwin Oyong Jul 07 '22 at 09:38
11

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 ..
hawkeye
  • 34,745
  • 30
  • 150
  • 304
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
Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
proximab
  • 1,865
  • 1
  • 13
  • 18