Created
March 31, 2021 08:15
-
-
Save elpsk/6e6334fe3f39e85dbaa0e862ab040e7d to your computer and use it in GitHub Desktop.
Update all local git projects and clean unused remotes
This file contains 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 | |
# Update all git directories below current directory or specified directory | |
# Skips directories that contain a file called .ignore | |
RED="\033[1;31m" | |
HIGHLIGHT="\033[1;32m" | |
NORMAL='\033[0m' | |
function update { | |
local d="$1" | |
if [ -d "$d" ]; then | |
if [ -e "$d/.ignore" ]; then | |
echo -e "\n${HIGHLIGHT}Ignoring $d${NORMAL}" | |
else | |
cd $d > /dev/null | |
if [ -d ".git" ]; then | |
echo -e "\n${HIGHLIGHT}Updating `pwd`$NORMAL" | |
git pull | |
#removing old github | |
REMOTE=`git remote -v` | |
if [[ $REMOTE == *"github.pixxxx.com"* ]]; then | |
echo -e "\n${RED}Cleaning old remote `pwd`$NORMAL" | |
git remote rm origin | |
fi | |
else | |
scan * | |
fi | |
cd .. > /dev/null | |
fi | |
fi | |
} | |
function scan { | |
for x in $*; do | |
update "$x" | |
done | |
} | |
if [ "$1" != "" ]; then cd $1 > /dev/null; fi | |
echo -e "${HIGHLIGHT}Scanning ${PWD}${NORMAL}" | |
scan * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment