Skip to content

Instantly share code, notes, and snippets.

@phette23
Last active May 21, 2024 18:33
Show Gist options
  • Save phette23/7620214 to your computer and use it in GitHub Desktop.
Save phette23/7620214 to your computer and use it in GitHub Desktop.
Shell script to run `git pull` inside all subdirectories which are git repositories. I keep a number of projects in a folder & this helps me avoid manually updating each.
#!/usr/bin/env fish
# similar script in Fish
# still under construction, need to quiet `git status` more effectively
function update -d 'Update git repo'
git stash --quiet
git pull
git stash apply --quiet
end
for dir in ./*/
cd $dir
git status -sb 2>/dev/null
if [ $status -eq 0 ]
set_color red
echo "Updating $dir…"
set_color normal
update
end
cd ..
end
#! /usr/bin/env bash
for dir in ./*/
do
cd ${dir}
git status >/dev/null 2>&1
# check if exit status of above was 0, indicating we're in a git repo
[ $(echo $?) -eq 0 ] && echo "Updating ${dir%*/}..." && git pull
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment