Skip to content

Instantly share code, notes, and snippets.

@jgriff
Last active April 15, 2019 15:43
Show Gist options
  • Save jgriff/ee9c6ac28b58fe1b892b8b88bf823ad2 to your computer and use it in GitHub Desktop.
Save jgriff/ee9c6ac28b58fe1b892b8b88bf823ad2 to your computer and use it in GitHub Desktop.
Recursively walks a directory and perform a git pull (if dir is a git repo). Ignores non-git directories.
#!/bin/bash
dir="$1"
display_prefix="$2"
# No directory has been provided, use current
if [ -z "$dir" ]
then
dir="`pwd`"
fi
# Make sure directory ends with "/"
if [[ $dir != */ ]]
then
dir="$dir/*"
else
dir="$dir*"
fi
# Loop all sub-directories
for f in $dir
do
# Only interested in directories
[ -d "${f}" ] || continue
# Check if directory is a git repository
if [ -d "$f/.git" ]
then
echo -n "Pulling "
echo -en "\033[0;34m"
echo -n $display_prefix
echo -n `basename $f`
echo -en "\033[0m"
echo -n "... "
git -C $f pull --rebase --prune --quiet &> /dev/null
if [ $? -eq 0 ]
then # everything is good
echo -en "\033[0;32m"
echo -n "✔ "
echo -e "\033[0m"
else # there are local changes
echo -en "\033[0;31m"
echo -n "✘ "
echo -e "\033[0m"
fi
else
# recurse into sub-directory
git-pull $f "${display_prefix}${f##*/}/"
fi
done
@jgriff
Copy link
Author

jgriff commented Mar 1, 2019

Installation

Place in your PATH.

Usage

From current directory,

$ git-pull

Or specify a specific directory (that you're not currently in),

$ git-pull some-other-dir

@jgriff
Copy link
Author

jgriff commented Mar 1, 2019

Also see git-status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment