Skip to content

Instantly share code, notes, and snippets.

@bolry
Last active November 3, 2023 21:35
Show Gist options
  • Save bolry/0fa87f9d1195864c51fe5ae16883f167 to your computer and use it in GitHub Desktop.
Save bolry/0fa87f9d1195864c51fe5ae16883f167 to your computer and use it in GitHub Desktop.
Update Git repositories available in the current directory and reset them to the status of a freshly cloned repository
#!/bin/bash
#set -o xtrace
set -o errexit
set -o nounset
set -o pipefail
IFS=$'\t\n'
unset CDPATH
for f in *
do
if [[ $(git -C "$f" rev-parse --is-inside-work-tree 2> /dev/null) == "true" ]]
then
echo -n "Update/pull of \`$f' ... "
git -C "$f" fetch origin --prune
git -C "$f" pull --rebase
git -C "$f" fetch origin --tags --force
elif [[ $(git -C "$f" rev-parse --is-bare-repository 2> /dev/null) == "true" ]]
then
echo -n "Update (bare) of \`$f' ... "
git -C "$f" fetch origin --prune --tags --force
else
echo "Skipping \`$f' for some reason"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment