Last active
November 3, 2023 21:35
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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