Created
December 6, 2011 14:35
-
-
Save mnem/1438396 to your computer and use it in GitHub Desktop.
Simple bash script for fetching and pulling all repos in the executed folder to the latest of the branch they are on
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/bash | |
################ | |
# Uncomment if you want the script to always use the scripts | |
# directory as the folder to look through | |
#REPOSITORIES="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
REPOSITORIES=`pwd` | |
IFS=$'\n' | |
for REPO in `ls "$REPOSITORIES/"` | |
do | |
if [ -d "$REPOSITORIES/$REPO" ] | |
then | |
echo "Updating $REPOSITORIES/$REPO at `date`" | |
if [ -d "$REPOSITORIES/$REPO/.git" ] | |
then | |
cd "$REPOSITORIES/$REPO" | |
git status | |
echo "Fetching" | |
git fetch | |
echo "Pulling" | |
git pull | |
else | |
echo "Skipping because it doesn't look like it has a .git folder." | |
fi | |
echo "Done at `date`" | |
echo | |
fi | |
done |
Recursive version of script
#!/bin/bash
################
sync_directory() {
IFS=$'\n'
for REPO in `ls "$1/"`
do
if [ -d "$1/$REPO" ]
then
echo "Updating $1/$REPO at `date`"
if [ -d "$1/$REPO/.git" ]
then
git -C "$1/$REPO" pull
else
sync_directory "$1/$REPO"
fi
echo "Done at `date`"
fi
done
}
REPOSITORIES="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
sync_directory $REPOSITORIES
I have a similar one, but I think the difference is that mine supports default branches
https://github.com/extremelogic-ph/xl_scripts/blob/master/xl_sync_git.sh
Thanks
Thank you!
Thanks!!!!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Following is one way to have it looping continuously, required a do-while and one additional line of code:
Runs every 10 seconds, change the number in
sleep 10
according to your needs. make it executable withsudo chmod +x yourFIleName.sh
, then run it with$ ./yourfileName.sh
- cool hack: If you start a screen you can have it running in the background:screen -S autopuller
and then run the script. To detach from the screen, press Ctrl + A and Ctrl + D !