Snippet: git-all-the-things.bash

From Tayledras
Jump to: navigation, search
GIT-ALL-THE-THINGS.BASH screenshot

Purpose

History

GIT-ALL-THE-THINGS.BASH was a bash script developed for Teaching Strategies, LLC, to quickly iterate through all child directories and pull the latest code from the git repository.

Bash Source

 1 #!/usr/local/bin/bash
 2 
 3 ## GIT-ALL-THE-THINGS.BASH :: This script will iterate through all child directories and perform a 'git pull' for each.
 4 
 5 ## ANSI escape codes for color
 6 ## Black        0;30     Dark Gray     1;30
 7 ## Red          0;31     Light Red     1;31
 8 ## Green        0;32     Light Green   1;32
 9 ## Brown/Orange 0;33     Yellow        1;33
10 ## Blue         0;34     Light Blue    1;34
11 ## Purple       0;35     Light Purple  1;35
12 ## Cyan         0;36     Light Cyan    1;36
13 ## Light Gray   0;37     White         1;37
14 ## No Color     '\033[0m'
15 
16 ## Define ANSI Colors
17 NC='\033[0m'        # No Color
18 BLACK='\033[0;30m'
19 RED='\033[0;31m'
20 GREEN='\033[0;32m'
21 ORANGE='\033[0;33m'
22 BLUE='\033[0;34m'
23 PURPLE='\033[0;35m'
24 CYAN='\033[0;36m'
25 LT_GREY='\033[0;37m'
26 DK_GREY='\033[1;30m'
27 LT_RED='\033[1;31m'
28 LT_GREEN='\033[1;32m'
29 YELLOW='\033[1;33m'
30 LT_BLUE='\033[1;34m'
31 LT_PURPLE='\033[1;35m'
32 LT_CYAN='\033[1;36m'
33 WHITE='\033[1;37m'
34 
35 echo -e "${LT_RED}## GIT-ALL-THE-THINGS.BASH :: This script will iterate through all child directories and perform a ${LT_GREY}'git pull'${LT_RED} for each.${NC}"
36 for f in *; do
37     if [ -d "$f" ]; then
38         # Will not run if no directories are available
39         cd $f 
40         echo -e "\n${YELLOW}## Pulling ${WHITE}${f}${YELLOW} from git repository...${NC}."
41         git config pull.rebase false    ## default strategy (merge)
42         git pull
43         echo -e "${LT_GREEN}## Finished pulling ${LT_CYAN} ${f}${LT_GREEN} from git repository...${NC}."
44         cd ..
45     fi
46 done
47 echo -e "${LT_RED}## GIT-ALL-THE-THINGS.BASH :: I'm done.${NC}"