Skip to content

Instantly share code, notes, and snippets.

@jabranr
Last active December 10, 2015 10:31
Show Gist options
  • Save jabranr/d45842aa9679fa2b62d9 to your computer and use it in GitHub Desktop.
Save jabranr/d45842aa9679fa2b62d9 to your computer and use it in GitHub Desktop.
Fetch and pull all Git directories in current directory
# 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