Reputation: 832
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?
Upvotes: 24
Views: 21595
Reputation: 49
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
Upvotes: 0
Reputation: 2473
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
Upvotes: 3
Reputation: 6040
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 }
Upvotes: 28
Reputation: 35732
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 ..
Upvotes: 12
Reputation: 2578
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.
Upvotes: 33