git-pull-recursive

#518
Raw
Author
winny
Created
June 21, 2022, 3:58 a.m.
Expires
Never
Size
476 bytes
Hits
203
Syntax
Bash
Private
No
#!/usr/bin/env bash
#
# Recursively search for git repos and run `git pull` on them.
#

set -eu -o pipefail

if [[ $# -eq 0 ]]; then
    search_root=.
else
    search_root="$1"
fi

find "$search_root" -name .git -print0 |
    while read -r -d $'\0' git_dir; do
        repo="${git_dir%/*}"
        tput setaf 2
        printf '>> Updating %s ...\n' "$repo"
        tput sgr0
        pushd "$repo" >/dev/null
        git pull
        popd >/dev/null
    done