Last Updated: February 25, 2016
·
538
· darklg

Pull all your Git Repositories

This shell script will pull all the Git repositories in a specific folder.

#!/bin/bash

dirhtd=/Users/kevin/websites/htdocs/*

for f in $dirhtd
do
    # Go to folder
    cd $f;
    # Check if it's a git repository
    if test -d ".git/"; then
        # Display repository name
        echo -e "\033[33m "$f" \033[0m";
        # Check repository status
        status=`git status -s`;
        # Git says nothing
        if [ -z "$status" ]
        then
            # Pull latest changes
            echo "- Pull";
            git pull --rebase;
        else
            # Do nothing
            echo "- Can’t pull";
        fi
    fi
done