Skip to content

Instantly share code, notes, and snippets.

@elpsk
Created March 31, 2021 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elpsk/6e6334fe3f39e85dbaa0e862ab040e7d to your computer and use it in GitHub Desktop.
Save elpsk/6e6334fe3f39e85dbaa0e862ab040e7d to your computer and use it in GitHub Desktop.
Update all local git projects and clean unused remotes
#!/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