Skip to content

Instantly share code, notes, and snippets.

@earendildev
Forked from phette23/update-repos.fish
Created August 25, 2022 04:03
Show Gist options
  • Save earendildev/b40b46955c4223d96eacd13b4ade5e8c to your computer and use it in GitHub Desktop.
Save earendildev/b40b46955c4223d96eacd13b4ade5e8c 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