Skip to content

Instantly share code, notes, and snippets.

@emtudo
Forked from gnumoksha/auto_sync_git.sh
Last active June 20, 2016 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emtudo/ada5010dfde0078f5788f2114e53c3ac to your computer and use it in GitHub Desktop.
Save emtudo/ada5010dfde0078f5788f2114e53c3ac to your computer and use it in GitHub Desktop.
Does the git pull of all subdirectories
#!/bin/bash
# This script syncs (i.e. makes git pull) on a specified directory or, se no
# parameter was specified, in all the subdirectories that are git projects.
#
# Usage:
# ./auto_sync_git.sh directory_of_my_project
# ./auto_sync_git.sh
# An alias to the git binary
GIT=$(which git)
# This function does the git pull
function make_pull {
directory="$1"; shift
cd $directory
# if the current dir is a git repository
# http://stackoverflow.com/questions/2180270/check-if-current-directory-is-a-git-repository
if [[ -d ".git" || $($GIT rev-parse --git-dir > /dev/null 2>&1) ]]; then
echo "Pulling $(pwd)"
$GIT pull
if [[ $? -eq 0 ]]; then
echo 'SUCCESS!'
else
echo 'FAILURE!'
fi
echo
fi
cd - > /dev/null
}
# The "main" function
function main {
if [[ -d "$1" ]]; then
make_pull "$1"
else
echo "Pulling all the subdirectories!"
for directory in $(find . -maxdepth 1 -type d); do
if [[ $directory != '.' && $directory != '..' ]]; then
make_pull $directory
fi
done
fi
}
# Invokes the main function and pass all script parameters to it
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment