I have my git repos cloned on my site. In order to keep my git viewer up to date, I need those clones to continue to be up to date.
Thankfully, there is a simple way to do this. git does have a –git-dir=/path, However this does not appear to work. You still need to change into the working directory in order to pull the updates. So after some work, I came up with this:
#!/bin/bash
FILES=/srv/git/*
for f in $FILES
do
if [ -d $f ] && [ -d $f/.git ]
then
echo "Processing Git repository, $f"
cd $f
git --git-dir="$f/.git" pull -q
fi;
done
I simply add this as a cron tab, using > /dev/null to eat the output. However if an error occurs, I should receive a email with what exactly went on.