From a parent folder, how do I get git to go to specific folders that all have the same suffix using a loop?

112 Views Asked by At

I have a parent folder named 'gitt' Inside this, I have four subfolders 'gitt1' 'gitt2' 'gitt3' 'gitt4'

Each of these four subfolders have a few folders, including a git repository folder which has the same name as the subfolder +1.0

E.g gitt1 has few folders, including its' repository : gitt11.0

gitt2 has few folders, including its' repository : gitt21.0 etc

From the parent folder gitt, I want a loop command that goes to each of the subfolders, finds the folder with the same name as the subfolder but ending in '1.0' then navigates into it, checks its' git status and goes back two levels up.

I have found this for /f "tokens=*" %a in ('dir /ad /b') do cd %a & git status & cd.. but it only does git status on the subfolders and does not go into the folders ending with 1.0

I do not want to make the parent folder(gitt) a repository.

1

There are 1 best solutions below

2
lit On

Use the command FOR /? to see the modifiers that can be applied to a path. This assumes that git can do a status on the directory path specified as a command line parameter. If not, CD may be needed.

FOR /F "tokens=*" %A IN ('DIR /AD /B "C:\src\t\gitt\gitt*"') DO @(ECHO git status "%~dpnxA\%~nxA1.0")

As always, double the PERCENT SIGN characters in a .bat file script.