Skip to content

Instantly share code, notes, and snippets.

@garraflavatra
Last active June 17, 2023 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garraflavatra/cd3b5861e1c508bcbf9aad58afdb6602 to your computer and use it in GitHub Desktop.
Save garraflavatra/cd3b5861e1c508bcbf9aad58afdb6602 to your computer and use it in GitHub Desktop.
Bash script that keeps all Git repositories within a specified directory up to date.
#!/usr/bin/bash
#
# This script keeps all Git repositories within a specified directory up to date.
#
# Consider the following example. The linux and curl repositories will be updated
# when you run this in the gitforks directory.
#
# gitforks/
# linux/.git/ linux Git repository
# curl/.git/ curl Git repository
# update.sh This script
# last_update.txt Contains last updated time.
#
# When the script is run, it puts the time of execution and the duration in a file
# called last_update.txt
#
# duration: 0:00.00
# time: Sat Jun 17 12:30:02 CEST 2023
#
# You can run this script automatically. For example, add the following to your
# crontab to run it every 15 minutes:
#
# */15 * * * * /home/user/gitforks/update.sh
#
# (c) Romein van Buren 2023
# SPDX-License-Identifier: WTFPL
#
set -e
cd /home/romein/gitforks
\time -f "duration: %E" -o last_update.txt ls -1 -d */ | xargs -P10 -I{} git -C {} pull
echo "time: $(date)" >> last_update.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment