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.
windows windows-8 windows-8.1 git cmd.exe
add a comment |
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.
windows windows-8 windows-8.1 git cmd.exe
are you sure this doesn't workc:sdf>for /D %i in (*.*) do (CD c:sdf%i && DIR && pause)
use the pause to troubleshoot. Another variation isc:sdf>for /D %i in (*.*) do (CD %i && DIR && CD .. && PAUSE)
andc:sdf>for /D %i in (*.*) do (PUSHD %i && DIR && POPD && PAUSE)
– barlop
Mar 20 '15 at 10:32
if you see the FOR is doing what you want, and get it to do what you want, then you can look at the GIT command
– barlop
Mar 20 '15 at 10:42
add a comment |
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.
windows windows-8 windows-8.1 git cmd.exe
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.
windows windows-8 windows-8.1 git cmd.exe
windows windows-8 windows-8.1 git cmd.exe
asked Mar 16 '15 at 11:48
A TA T
481525
481525
are you sure this doesn't workc:sdf>for /D %i in (*.*) do (CD c:sdf%i && DIR && pause)
use the pause to troubleshoot. Another variation isc:sdf>for /D %i in (*.*) do (CD %i && DIR && CD .. && PAUSE)
andc:sdf>for /D %i in (*.*) do (PUSHD %i && DIR && POPD && PAUSE)
– barlop
Mar 20 '15 at 10:32
if you see the FOR is doing what you want, and get it to do what you want, then you can look at the GIT command
– barlop
Mar 20 '15 at 10:42
add a comment |
are you sure this doesn't workc:sdf>for /D %i in (*.*) do (CD c:sdf%i && DIR && pause)
use the pause to troubleshoot. Another variation isc:sdf>for /D %i in (*.*) do (CD %i && DIR && CD .. && PAUSE)
andc:sdf>for /D %i in (*.*) do (PUSHD %i && DIR && POPD && PAUSE)
– barlop
Mar 20 '15 at 10:32
if you see the FOR is doing what you want, and get it to do what you want, then you can look at the GIT command
– barlop
Mar 20 '15 at 10:42
are you sure this doesn't work
c:sdf>for /D %i in (*.*) do (CD c:sdf%i && DIR && pause)
use the pause to troubleshoot. Another variation is c:sdf>for /D %i in (*.*) do (CD %i && DIR && CD .. && PAUSE)
and c:sdf>for /D %i in (*.*) do (PUSHD %i && DIR && POPD && PAUSE)
– barlop
Mar 20 '15 at 10:32
are you sure this doesn't work
c:sdf>for /D %i in (*.*) do (CD c:sdf%i && DIR && pause)
use the pause to troubleshoot. Another variation is c:sdf>for /D %i in (*.*) do (CD %i && DIR && CD .. && PAUSE)
and c:sdf>for /D %i in (*.*) do (PUSHD %i && DIR && POPD && PAUSE)
– barlop
Mar 20 '15 at 10:32
if you see the FOR is doing what you want, and get it to do what you want, then you can look at the GIT command
– barlop
Mar 20 '15 at 10:42
if you see the FOR is doing what you want, and get it to do what you want, then you can look at the GIT command
– barlop
Mar 20 '15 at 10:42
add a comment |
4 Answers
4
active
oldest
votes
This works for me in a batch file in CMD:
for /d %%i in (*.*) do cd %%i & git pull & cd..
(Thank you for all great tips I get on this site!)
Thanks, that worked. Replace%%
with%
when running purely on CMD (not in a script).
– A T
Apr 20 '17 at 6:14
add a comment |
Couldn't this be a simple one-liner in Powershell?
Example:
Resolve-Path D:workrepos*.git | foreach { cd $_; git pull }
I'd prefer to use Windows Batch; is there no way to make the aforementionedfor
-loop work?
– A T
Mar 16 '15 at 20:51
Powershell is the de facto shell on Windows. Cmd will be deprecated in the future. There's no use in trying to cobble something together in cmd when there's an object oriented Windows shell right at your fingertips which makes everything so much easier. -my two cents :-)
– megamorf
Mar 17 '15 at 8:19
1
Really? - Well alright, just change your code toD:workrepos*
and I'll accept.
– A T
Mar 18 '15 at 9:18
The Resolve-Path command as I posted it automatically gets all the folders in repos and then looks for a folder called .git in each of them. That's where you want to cd into according to your code. It's a pretty elegant solution. If you remove the pipe and everything after it you'll see that it gives you all of the .git folders.
– megamorf
Mar 18 '15 at 9:23
add a comment |
I suggest to use git pull <repository>
syntax instead on Git Shell with cmd.exe
default shell setting, and look up setlocal enabledelayedexpansion
for variable initialization (set
) inside for
loop.
add a comment |
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.
add a comment |
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f890165%2fwindows-for-loop-through-dirs-run-git-pull%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
This works for me in a batch file in CMD:
for /d %%i in (*.*) do cd %%i & git pull & cd..
(Thank you for all great tips I get on this site!)
Thanks, that worked. Replace%%
with%
when running purely on CMD (not in a script).
– A T
Apr 20 '17 at 6:14
add a comment |
This works for me in a batch file in CMD:
for /d %%i in (*.*) do cd %%i & git pull & cd..
(Thank you for all great tips I get on this site!)
Thanks, that worked. Replace%%
with%
when running purely on CMD (not in a script).
– A T
Apr 20 '17 at 6:14
add a comment |
This works for me in a batch file in CMD:
for /d %%i in (*.*) do cd %%i & git pull & cd..
(Thank you for all great tips I get on this site!)
This works for me in a batch file in CMD:
for /d %%i in (*.*) do cd %%i & git pull & cd..
(Thank you for all great tips I get on this site!)
answered Mar 16 '17 at 15:08
user708180user708180
561
561
Thanks, that worked. Replace%%
with%
when running purely on CMD (not in a script).
– A T
Apr 20 '17 at 6:14
add a comment |
Thanks, that worked. Replace%%
with%
when running purely on CMD (not in a script).
– A T
Apr 20 '17 at 6:14
Thanks, that worked. Replace
%%
with %
when running purely on CMD (not in a script).– A T
Apr 20 '17 at 6:14
Thanks, that worked. Replace
%%
with %
when running purely on CMD (not in a script).– A T
Apr 20 '17 at 6:14
add a comment |
Couldn't this be a simple one-liner in Powershell?
Example:
Resolve-Path D:workrepos*.git | foreach { cd $_; git pull }
I'd prefer to use Windows Batch; is there no way to make the aforementionedfor
-loop work?
– A T
Mar 16 '15 at 20:51
Powershell is the de facto shell on Windows. Cmd will be deprecated in the future. There's no use in trying to cobble something together in cmd when there's an object oriented Windows shell right at your fingertips which makes everything so much easier. -my two cents :-)
– megamorf
Mar 17 '15 at 8:19
1
Really? - Well alright, just change your code toD:workrepos*
and I'll accept.
– A T
Mar 18 '15 at 9:18
The Resolve-Path command as I posted it automatically gets all the folders in repos and then looks for a folder called .git in each of them. That's where you want to cd into according to your code. It's a pretty elegant solution. If you remove the pipe and everything after it you'll see that it gives you all of the .git folders.
– megamorf
Mar 18 '15 at 9:23
add a comment |
Couldn't this be a simple one-liner in Powershell?
Example:
Resolve-Path D:workrepos*.git | foreach { cd $_; git pull }
I'd prefer to use Windows Batch; is there no way to make the aforementionedfor
-loop work?
– A T
Mar 16 '15 at 20:51
Powershell is the de facto shell on Windows. Cmd will be deprecated in the future. There's no use in trying to cobble something together in cmd when there's an object oriented Windows shell right at your fingertips which makes everything so much easier. -my two cents :-)
– megamorf
Mar 17 '15 at 8:19
1
Really? - Well alright, just change your code toD:workrepos*
and I'll accept.
– A T
Mar 18 '15 at 9:18
The Resolve-Path command as I posted it automatically gets all the folders in repos and then looks for a folder called .git in each of them. That's where you want to cd into according to your code. It's a pretty elegant solution. If you remove the pipe and everything after it you'll see that it gives you all of the .git folders.
– megamorf
Mar 18 '15 at 9:23
add a comment |
Couldn't this be a simple one-liner in Powershell?
Example:
Resolve-Path D:workrepos*.git | foreach { cd $_; git pull }
Couldn't this be a simple one-liner in Powershell?
Example:
Resolve-Path D:workrepos*.git | foreach { cd $_; git pull }
answered Mar 16 '15 at 12:06
megamorfmegamorf
1,346714
1,346714
I'd prefer to use Windows Batch; is there no way to make the aforementionedfor
-loop work?
– A T
Mar 16 '15 at 20:51
Powershell is the de facto shell on Windows. Cmd will be deprecated in the future. There's no use in trying to cobble something together in cmd when there's an object oriented Windows shell right at your fingertips which makes everything so much easier. -my two cents :-)
– megamorf
Mar 17 '15 at 8:19
1
Really? - Well alright, just change your code toD:workrepos*
and I'll accept.
– A T
Mar 18 '15 at 9:18
The Resolve-Path command as I posted it automatically gets all the folders in repos and then looks for a folder called .git in each of them. That's where you want to cd into according to your code. It's a pretty elegant solution. If you remove the pipe and everything after it you'll see that it gives you all of the .git folders.
– megamorf
Mar 18 '15 at 9:23
add a comment |
I'd prefer to use Windows Batch; is there no way to make the aforementionedfor
-loop work?
– A T
Mar 16 '15 at 20:51
Powershell is the de facto shell on Windows. Cmd will be deprecated in the future. There's no use in trying to cobble something together in cmd when there's an object oriented Windows shell right at your fingertips which makes everything so much easier. -my two cents :-)
– megamorf
Mar 17 '15 at 8:19
1
Really? - Well alright, just change your code toD:workrepos*
and I'll accept.
– A T
Mar 18 '15 at 9:18
The Resolve-Path command as I posted it automatically gets all the folders in repos and then looks for a folder called .git in each of them. That's where you want to cd into according to your code. It's a pretty elegant solution. If you remove the pipe and everything after it you'll see that it gives you all of the .git folders.
– megamorf
Mar 18 '15 at 9:23
I'd prefer to use Windows Batch; is there no way to make the aforementioned
for
-loop work?– A T
Mar 16 '15 at 20:51
I'd prefer to use Windows Batch; is there no way to make the aforementioned
for
-loop work?– A T
Mar 16 '15 at 20:51
Powershell is the de facto shell on Windows. Cmd will be deprecated in the future. There's no use in trying to cobble something together in cmd when there's an object oriented Windows shell right at your fingertips which makes everything so much easier. -my two cents :-)
– megamorf
Mar 17 '15 at 8:19
Powershell is the de facto shell on Windows. Cmd will be deprecated in the future. There's no use in trying to cobble something together in cmd when there's an object oriented Windows shell right at your fingertips which makes everything so much easier. -my two cents :-)
– megamorf
Mar 17 '15 at 8:19
1
1
Really? - Well alright, just change your code to
D:workrepos*
and I'll accept.– A T
Mar 18 '15 at 9:18
Really? - Well alright, just change your code to
D:workrepos*
and I'll accept.– A T
Mar 18 '15 at 9:18
The Resolve-Path command as I posted it automatically gets all the folders in repos and then looks for a folder called .git in each of them. That's where you want to cd into according to your code. It's a pretty elegant solution. If you remove the pipe and everything after it you'll see that it gives you all of the .git folders.
– megamorf
Mar 18 '15 at 9:23
The Resolve-Path command as I posted it automatically gets all the folders in repos and then looks for a folder called .git in each of them. That's where you want to cd into according to your code. It's a pretty elegant solution. If you remove the pipe and everything after it you'll see that it gives you all of the .git folders.
– megamorf
Mar 18 '15 at 9:23
add a comment |
I suggest to use git pull <repository>
syntax instead on Git Shell with cmd.exe
default shell setting, and look up setlocal enabledelayedexpansion
for variable initialization (set
) inside for
loop.
add a comment |
I suggest to use git pull <repository>
syntax instead on Git Shell with cmd.exe
default shell setting, and look up setlocal enabledelayedexpansion
for variable initialization (set
) inside for
loop.
add a comment |
I suggest to use git pull <repository>
syntax instead on Git Shell with cmd.exe
default shell setting, and look up setlocal enabledelayedexpansion
for variable initialization (set
) inside for
loop.
I suggest to use git pull <repository>
syntax instead on Git Shell with cmd.exe
default shell setting, and look up setlocal enabledelayedexpansion
for variable initialization (set
) inside for
loop.
answered Mar 20 '15 at 2:25
w17tw17t
2,36741740
2,36741740
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Feb 12 at 13:22
JörgJörg
54767
54767
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f890165%2fwindows-for-loop-through-dirs-run-git-pull%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
are you sure this doesn't work
c:sdf>for /D %i in (*.*) do (CD c:sdf%i && DIR && pause)
use the pause to troubleshoot. Another variation isc:sdf>for /D %i in (*.*) do (CD %i && DIR && CD .. && PAUSE)
andc:sdf>for /D %i in (*.*) do (PUSHD %i && DIR && POPD && PAUSE)
– barlop
Mar 20 '15 at 10:32
if you see the FOR is doing what you want, and get it to do what you want, then you can look at the GIT command
– barlop
Mar 20 '15 at 10:42