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
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.
-
1If that is not an option try the techniques described here: addyosmani.com/blog/backing-up-a-github-account– eikoocCommented 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!– ROODAYCommented Jun 15, 2014 at 23:54
-
1I believe this is exactly what you are looking for: stackoverflow.com/questions/17099564/… Correct me if I'm wrong– eikoocCommented Jun 16, 2014 at 17:44
-
1I have edited the answer a bit to incorporate a better answer– eikoocCommented Jun 17, 2014 at 21:34
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 }
-
1I went a bit further and created an alias in my PS profile to call
Git-Pull-All
with this sample: stackoverflow.com/a/29806921/228160 Full gist -> gist.github.com/yzraeu/12b96c409ae7da29b1a41ddccec3a0c3 Commented Apr 28, 2021 at 5:27 -
For macOS bash version: stackoverflow.com/a/60786488/10158227 Commented Jul 7, 2022 at 9:38
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 ..
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
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