Last active
September 6, 2017 05:40
-
-
Save hmdmph/56c7983f144d3e835ab82d2c03c93007 to your computer and use it in GitHub Desktop.
Update all git repositories in a folder
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 repositories in give folder | |
COLOR_NONE="\033[0m" | |
COLOR_1="\033[1;34m" | |
# making changes to shell options, affects regular expressions | |
shopt -s extglob nullglob | |
# check whether 1 arugment passed, if so then use it as base directory, else use current director as base directory | |
# dont put ending '/'' in folder | |
basedir="." | |
if [ -z "$1" ] | |
then | |
basedir=$(pwd) | |
else | |
basedir="$1" | |
fi | |
# check whether 2 arugments passed, if so then use the second one as director to skip | |
# dont put ending '/' in folder | |
skipdir= | |
if [ -z "$2" ] | |
then | |
skipdir="" | |
else | |
skipdir="$2" | |
fi | |
# create array of sub folders | |
if [[ -z $skipdir ]]; then | |
folder_array=( "$basedir"/*/ ) | |
else | |
folder_array=( "$basedir"/!($skipdir)/ ) | |
fi | |
# going through the sub folder and pull | |
for i in ${folder_array[@]}; do | |
if [ -e "$i/.git" ]; then | |
# go to directory | |
cd $i > /dev/null | |
branch=$(git rev-parse --abbrev-ref HEAD); | |
repo_name=${i/$basedir/""} | |
echo -e "\n${COLOR_1}Updating ${repo_name%/} - $branch${COLOR_NONE}\n" | |
# fetch | |
git fetch | |
# pull | |
git pull origin $branch | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update all git repositories in a folder. There are two optional arguments that you can pass while running the script.
Usage ./update-git-repos.sh <folder_path> <folder_name_to_skip>
update-git-repos.sh
chmod +x update-git-repos.sh
./update-git-repos.sh root_folder_path folder_name_to_skip
If no arguments passed it update all git repositories in the current directory without skipping any folder