Windows for loop through dirs, run git pull?












3















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.









share|improve this question























  • 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
















3















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.









share|improve this question























  • 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














3












3








3


1






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.









share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 16 '15 at 11:48









A TA T

481525




481525













  • 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



















  • 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

















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










4 Answers
4






active

oldest

votes


















4














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!)






share|improve this answer
























  • Thanks, that worked. Replace %% with % when running purely on CMD (not in a script).

    – A T
    Apr 20 '17 at 6:14



















3














Couldn't this be a simple one-liner in Powershell?



Example:



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





share|improve this answer
























  • 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






  • 1





    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





















0














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.






share|improve this answer































    0














    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.






    share|improve this answer
























      Your Answer








      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      4














      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!)






      share|improve this answer
























      • Thanks, that worked. Replace %% with % when running purely on CMD (not in a script).

        – A T
        Apr 20 '17 at 6:14
















      4














      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!)






      share|improve this answer
























      • Thanks, that worked. Replace %% with % when running purely on CMD (not in a script).

        – A T
        Apr 20 '17 at 6:14














      4












      4








      4







      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!)






      share|improve this answer













      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!)







      share|improve this answer












      share|improve this answer



      share|improve this answer










      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



















      • 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













      3














      Couldn't this be a simple one-liner in Powershell?



      Example:



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





      share|improve this answer
























      • 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






      • 1





        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


















      3














      Couldn't this be a simple one-liner in Powershell?



      Example:



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





      share|improve this answer
























      • 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






      • 1





        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
















      3












      3








      3







      Couldn't this be a simple one-liner in Powershell?



      Example:



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





      share|improve this answer













      Couldn't this be a simple one-liner in Powershell?



      Example:



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






      share|improve this answer












      share|improve this answer



      share|improve this answer










      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 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






      • 1





        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





















      • 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






      • 1





        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



















      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













      0














      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.






      share|improve this answer




























        0














        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.






        share|improve this answer


























          0












          0








          0







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 20 '15 at 2:25









          w17tw17t

          2,36741740




          2,36741740























              0














              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.






              share|improve this answer




























                0














                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.






                share|improve this answer


























                  0












                  0








                  0







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 12 at 13:22









                  JörgJörg

                  54767




                  54767






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                      is 'sed' thread safe

                      How to make a Squid Proxy server?