Last active
April 26, 2024 17:26
-
-
Save hqrd/b5d5361b65b077c57fe1c980cd7cf551 to your computer and use it in GitHub Desktop.
This script is used to synchronize all the git repositories in a directory at once using 'hub sync'
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/sh | |
usage () | |
{ | |
echo "Usage: $(basename "$0") [mode]" | |
echo " Options:" | |
echo " - mode: fetch or pull" | |
} | |
function error_exit () | |
{ | |
echo "$1" 1>&2 | |
usage | |
exit 1 | |
} | |
WORKING_DIRECTORY=`C:\Users\Julien\Documents\dkt\git` | |
echo "Updating all repositories in ${WORKING_DIRECTORY}" | |
if [ -z "$1" ] | |
then | |
echo "No mode provided. Using default mode." | |
MODE="hub sync" | |
elif [ "$1" = "pull" ] | |
then | |
MODE="git pull -v" | |
elif [ "$1" = "fetch" ] | |
then | |
MODE="git fetch -v" | |
else | |
error_exit "ERROR: unknown mode $1" | |
fi | |
echo "Using mode: $MODE" | |
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && if [ -d '.git' ]; then echo 'Found git repository:'; pwd; echo 'Updating..'; git remote prune origin; git gc; $MODE; echo 'Done.'; fi;" \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment