aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/git-update-all.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/bin/git-update-all.sh b/bin/git-update-all.sh
new file mode 100755
index 0000000..a786682
--- /dev/null
+++ b/bin/git-update-all.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+## SPDX-FileCopyrightText: 2022 M. Shulhan <ms@kilabit.info>
+## SPDX-License-Identifier: GPL-3.0-or-later
+
+## Script to fetch the latest commits from all git repositories under a
+## directory.
+##
+## Usage:
+##
+## $ git-update-all.sh $dir
+##
+## Where $dir is a path to directory that contains one or more repositories.
+
+DIR=${1:-.}
+
+echo "Updating all git repositories in $DIR"
+
+dirs=$(find -L "$DIR" -maxdepth 1 -mindepth 1 -type d -print)
+
+for repo in $dirs; do
+ if [[ ! -d "$repo/.git" ]]; then
+ continue
+ fi
+
+ echo ""
+ echo ">>> updating $repo ..."
+ git -C $repo stash --quiet
+ git -C $repo pull --rebase
+ git -C $repo gc --prune=now --quiet
+ git -C $repo stash pop --quiet
+ git -C $repo fetch --prune --prune-tags
+done