Windows for-Schleife durch Verzeichnisse, „git pull“ ausführen?

Windows for-Schleife durch Verzeichnisse, „git pull“ ausführen?

Von Bash aus ist es einfach:

for d in *; do GIT_DIR="$d/.git" git pull; done

Oder:

for d in *; do GIT_DIR="$PWD/$d/.git" git pull; done

Über die Windows-Eingabeaufforderung ist es jedoch nicht ganz so einfach. Ich habe Folgendes versucht:

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"

Aber nichts davon funktioniert. Ich erhalte immer einen dieser Fehler:

fatal: unable to access '"repo-name/.git" /config': Invalid argument
The system cannot find the path specified.

Antwort1

Bei mir funktioniert das in einer Batchdatei in CMD:

for /d %%i in (*.*) do cd %%i & git pull & cd..

Antwort2

Könnte dies nicht ein einfacher Einzeiler in Powershell sein?

Beispiel:

Resolve-Path D:\work\repos\*\.git | foreach { cd $_; git pull }

Antwort3

Eintreten powershellinExplorer-AdressfeldIhrerBasisordnerUnddrücke Enter. Führen Sie dann Folgendes aus:

Get-ChildItem . -exclude *.ps1,temp,*.txt | foreach { cd $_; Write-Host "`r`n" $_; Git pull '-v' }

Verwenden Sie diesen Ansatz, wenn Resolve-Pather für Sie nicht funktioniert.

Antwort4

git pull <repository>Ich schlage vor , stattdessen die Syntax der Git-Shell mit den Standard-Shell-Einstellungen zu verwenden und innerhalb der Schleife nach der Variableninitialisierung ( ) cmd.exezu suchen .setlocal enabledelayedexpansionsetfor

verwandte Informationen