aboutsummaryrefslogtreecommitdiff
path: root/bin/git-update-all.sh
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-09-18 01:49:23 +0700
committerShulhan <ms@kilabit.info>2022-09-18 03:20:49 +0700
commit15ba9c8fb84094744288c84b1d1cdc1bb8d33096 (patch)
tree2f4da6b39336e2eb807eaf42cbb10c6e93fce60e /bin/git-update-all.sh
parent36bc0c7fb5df2b9dfebb9be153ccdea46c0b3d80 (diff)
downloadbin.sh-15ba9c8fb84094744288c84b1d1cdc1bb8d33096.tar.xz
all: add script git-update-all.sh
This script fetch the latest commits from all git repositories under a directory.
Diffstat (limited to 'bin/git-update-all.sh')
-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