1

This answer is for linux command line. I need the same for Windows command line. I created the following using this, but my code does not work.

for /D /r %i in (*.*) do (cd %i && echo %i && git pull && cd ..)

Update

From @SevenEleven's answer and @kostix's comment the following worked.

for /D %%i in (.\*) do (cd "%%i" && git pull && cd..)

or

for /D %%i in (*) do (cd "%%i" & git pull && cd..)
Community
  • 1
  • 1
Stat-R
  • 5,040
  • 8
  • 42
  • 68
  • If anyone has a version which checks whether we're on the default branch (e.g. `master` or `develop`) before doing the pull, and halts if not, that would be really cool! – Vincent Sels Sep 01 '22 at 13:19

1 Answers1

6

This should do the job:

for /D %%i in (.\*) do (cd %%i && echo %%i && git pull && cd ..)

This script searches the subdirectories of the current directory (for /D %%i in (.\*)). It changes to every directory found (cd %%i), writes its name to console (echo %%i) and executes git pull

/r does search all subdirectories too. Since you don't want to search your projects subdirectories, that is not needed. If you search an absolute path, you can get rid of the cd ..:

SevenEleven
  • 2,326
  • 2
  • 32
  • 32
  • 3
    @stat-r, one thing to note is that `%%` is for batcn files; if you will want to first test this in plain `cmd.exe`, use a single `%`. Another thing is that I would surround each `%%i` with double quotes -- to catch a possible case of a directory name containing spaces in it. – kostix Nov 23 '15 at 18:23
  • @Stat-R Yes, that's right. That's because of the relative path. If you search in an absolute path, this example should work without `cd ..` – SevenEleven Nov 23 '15 at 20:02