Skip to content

Instantly share code, notes, and snippets.

@svagionitis
Created September 8, 2021 06:44
Show Gist options
  • Save svagionitis/eb00df57e6d521a90deeae0bd48b82a8 to your computer and use it in GitHub Desktop.
Save svagionitis/eb00df57e6d521a90deeae0bd48b82a8 to your computer and use it in GitHub Desktop.
Git fetch git repos in directories recursively
#!/bin/sh -eu
# Git fetch git repos in directories recursively
usage()
{
echo "Usage: $0 <directory>"
}
if [ -z "${1}" ]; then
usage
exit 1
fi
INPUT_DIR=${1}
# See https://stackoverflow.com/questions/11981716/how-to-quickly-find-all-git-repos-under-a-directory
GIT_REPOS_DIR=$(find "${INPUT_DIR}" -type d -execdir test -d {}/.git \; -prune -print)
for dir in ${GIT_REPOS_DIR}; do
cd "${dir}"
echo "Updating git repo in ${dir}"
git fetch --all
cd -
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment