Perform single action for every subdirectory
I am using git to manage my repositories. it can perform action only to the current directory/repository.
I have directories structure like the following:
myRepos
|
--repo 1
--repo 2
--repo A
--repo B
I want to perform single action on every subdirectory like this:
pushd repo 1
git pull
popd
pushd repo 2
git pull
popd
pushd repo A
git pull
popd
pushd repo B
git pull
popd
The subdirectories can be changed when adding removing new repos and the command like can be changed.
I want to be able to use the bash file like that:
git-all.sh commit -m"." -a
Then, it will perform "git commit -m"." -a " instead of git pull for every sub directory.
Any ideas how to manage that?
for i in myrepos/*/; do pushd "$i" && { git pull; popd }; done
should do the trick.
for i in myrepos/*/
for
runs the following commands once for every directory, copying the path into $i
.
pushd "$i"
Temporarily cd
s into the directory at $i
git pull
Fetches repo from remote
popd
Returns to the directory the command was run