Created
November 9, 2020 23:55
-
-
Save melroy89/62988f2800dcaa12b0a2b844c9de4523 to your computer and use it in GitHub Desktop.
Pull/push all your Git repos Bash script (Origin: https://gitlab.melroy.org/-/snippets/40)
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
#!/usr/bin/env bash | |
# Script that goes through all my git repos and update them. And report any untracked files. | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
ORANGE='\033[0;33m' | |
NC='\033[0m' # No Color | |
# Do not add automatically to staged area, but only pull & push all repos | |
CURRENT="$(dirname "$(realpath "$0")")" | |
for dir in */;do | |
cd "$CURRENT/$dir" | |
echo "INFO: processing ${dir%/}" | |
BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
if [ ! -z $BRANCH ]; then | |
if [[ "$BRANCH" =~ ^(master|main)$ ]]; then | |
UNTRACKED_FILES=$(git ls-files --others --exclude-standard) | |
if [ ! -z "$UNTRACKED_FILES" ]; then | |
echo -e "${ORANGE}WARN:${NC} some files are untracked! List of untracked files:" | |
echo "$UNTRACKED_FILES" | |
fi | |
git pull --quiet && git push --quiet | |
ret=$? | |
if [ $ret -ne 0 ]; then | |
echo -e "${RED}ERROR:${NC} Something went wrong during git pull/push.\n" | |
else | |
echo -e "${GREEN}DONE:${NC} ${dir%/} is now up-to-date and pushed successfully." | |
fi | |
else | |
echo -e "${ORANGE}WARN:${NC} Skipping ${dir%/}, current branch is not master or main." | |
fi | |
else | |
echo -e "${ORANGE}WARN:${NC} Skipping ${dir%/}, directory has no git repo." | |
fi | |
echo "-----------" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is just a mirror from the one on GitLab. See my original snippet: https://gitlab.melroy.org/-/snippets/40