Last active
December 10, 2015 10:31
-
-
Save jabranr/d45842aa9679fa2b62d9 to your computer and use it in GitHub Desktop.
Fetch and pull all Git directories in current directory
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
# Use the script at root directory of all Git projects. | |
# | |
# How it works: | |
# 1. The script will change directory to each sub directory. | |
# 2. Checks for ".git/" directory. Fails and returns message if not found. | |
# 3. In valid Git project, it Fetches and Pulls the updates from remote. | |
# 4. Shows end result message accordingly. | |
# | |
# Author: Jabran Rafique <[email protected]> | |
# License: MIT License | |
#!/bin/bash | |
REPOS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
RED="\033[0;31m" | |
GREEN="\033[0;32m" | |
ORANGE="\033[0;33m" | |
LIGHTGRAY="\033[0;37m" | |
NC="\033[0m" | |
for REPO in `ls "$REPOS/"` | |
do | |
if [ -d "$REPOS/$REPO" ] | |
then | |
echo -e "${ORANGE}Checking${NC} ${LIGHTGRAY}$REPOS/$REPO${NC}" | |
if [ -d "$REPOS/$REPO/.git" ] | |
then | |
cd "$REPOS/$REPO" | |
echo -e "${ORANGE}Current branch is:" | |
git branch | |
echo -e "${NC}" | |
echo -e "${ORANGE}Fetching...${NC}" | |
git fetch | |
echo -e "${ORANGE}Pulling...${NC}" | |
git pull | |
echo -e "${GREEN}Updated the repository with remote at `date`${NC}" | |
else | |
echo -e "${RED}$REPOS/$REPO is not a GIT respository.${NC}" | |
fi | |
git status | |
echo -e "${GREEN}Completed at `date`" | |
echo -e "${LIGHTGRAY}------------------------------------------------------------------${NC}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment