Bash: Show GIT Remote Origin for each immediate subfolder
To print on screen all the immediate subfolders and their GIT Remote Origin URL configuration we used the following command
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && echo '{}' && git config --get remote.origin.url" \;
We used the find
general command to get all folders that are in depth 1
, in other words all folders that are in the specific folder where we started the search.
In our case we used the dot
as the starting folder which means that it will run the find in the same folder as we were navigating in.
We passed as a parameter the -type d
to instruct find
to show only folders and ignore the files.
The \( ! -name . \)
prevents executing the command in current directory by removing it from the result set.
With the results we executed some commands on each.
Specifically, we created a new bash session for each result that navigated in the folder, printed out the name of the matched folder and then print the Remote Origin URL using the command git config --get remote.origin.url