32 lines
777 B
Bash
Executable File
32 lines
777 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
if [ ! -d "$HOME/GitProjects" ]; then
|
|
mkdir "$HOME/GitProjects"
|
|
fi
|
|
|
|
WORKPATH="$HOME/GitProjects"
|
|
|
|
readarray -t dirs < <(find "$WORKPATH" -mindepth 1 -maxdepth 1 -type d -printf '%P\n')
|
|
|
|
for dir in "${dirs[@]}"; do
|
|
# go into GitProjects directory
|
|
cd "$WORKPATH"
|
|
# output directory you're currently working on
|
|
printf "Working on ${dir}\n"
|
|
# change into that directory
|
|
cd "$dir"
|
|
# try to check out master or main branch
|
|
git checkout -q master 2>/dev/null \
|
|
|| git checkout -q main 2>/dev/null
|
|
# check whether the previous two commands failed
|
|
if [ $? -ne 0 ]; then
|
|
printf "Couldn't find master or main branches\n"
|
|
exit 1
|
|
fi
|
|
git fetch --all
|
|
git pull
|
|
done
|
|
|
|
exit 0
|