Windows for loop through dirs, run git pull?
From Bash it's simple:
for d in *; do GIT_DIR="$d/.git" git pull; done
Or:
for d in *; do GIT_DIR="$PWD/$d/.git" git pull; done
However from Windows Command Prompt it's not quite as simple. I've tried:
for /D %i in (*.*) do cd "%i" && git pull
for /D %i in (*.*) do cd "<absolute_path>\%i" && git pull
for /D %i in (*.*) do set GIT_DIR="<absolute_path>\%i\.git git pull"
for /D %i in (*.*) do set GIT_DIR="<absolute_path>\%i\.git && git pull"
But none work. Always getting one of these errors:
fatal: unable to access '"repo-name/.git" /config': Invalid argument
The system cannot find the path specified.
Solution 1:
This works for me in a batch file in CMD:
for /d %%i in (*.*) do cd %%i & git pull & cd..
Solution 2:
Couldn't this be a simple one-liner in Powershell?
Example:
Resolve-Path D:\work\repos\*\.git | foreach { cd $_; git pull }
Solution 3:
Enter powershell
into Explorer address field of your base folder and hit enter. Then execute:
Get-ChildItem . -exclude *.ps1,temp,*.txt | foreach { cd $_; Write-Host "`r`n" $_; Git pull '-v' }
Use this approach, if Resolve-Path
won't work for you.