Skip to content

Instantly share code, notes, and snippets.

@carlosm3011
Last active March 18, 2019 18:23
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 carlosm3011/447a35d189a951fbc02bb13485ba41b0 to your computer and use it in GitHub Desktop.
Save carlosm3011/447a35d189a951fbc02bb13485ba41b0 to your computer and use it in GitHub Desktop.
Automatically update and push git repositories found in a folder.
#!/bin/bash
###################################################################
# auto repository manager helper script
#
# Scans current directory for all folders ending in ".git", changes
# into those folders and either runs git pull or git push
#
# 2019-03-18
###################################################################
REPOS=$(find . -type d -depth 1 -name "*git")
update()
{
for repo in $REPOS
do
echo "%%% Updating $repo"
cd $repo
git pull
cd ..
echo
echo
done
}
push()
{
for repo in $REPOS
do
echo "%%% Auto commit $repo"
cd $repo
if [ -f NOCOMMIT ]; then
echo "Not committing or pushing $repo, NOCOMMIT exists"
else
git commit -a -m "auto commit"
echo "%%% Pushing $repo"
git push
fi
cd ..
echo
echo
done
}
CMD=$1
case $CMD in
update)
echo "CMD Updating all *.git repositories"
echo
update
;;
push)
echo "CMD Pushing all *.git repositories"
echo
push
;;
*)
echo "ERROR - Unknown command"
echo "Usage ./auto_repo.sh update|push"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment