Git/Shell: batch git pull, one-click update of multiple repositories in the same directory (quickly pull all projects)

May 26, 2020 version-2.0

git_pull_Batch.sh

#!/bin/bash

function showGreen(){ echo -e "\033[32m $1 \033[0m"}
function showBlue(){ echo -e "\033[36m $1 \033[0m"}
function showYellow(){ echo -e "\033[33m $1 \033[0m"}
function showWhite(){ echo -e "\033[37m $1 \033[0m"}

function  traversal_dir ( ) { 
    for  sub_dir  in  ` ls $1 `  # Traverse out subdirectories through ls root_dir, load subdirectory sub_dir into 
    do 
        dir = $1 "/" $sub_dir  # Combine root directory $1 and subdirectory sub_dir into a complete directory 
        if  [ -d $dir  ] #Judgment  : it is the next step in the directory 
        then 
            cd  $dir 
			showBlue $dir 
            showGreen 'git pull ' $sub_dir 
            git pull
			 echo #Print  blank lines 
        else 
            showYellow $dir 
			echo #Print  blank lines 
        fi  
    done
}

root_dir = "N:\Desktop\qnit" #Define the  root directory, that is, the parent directory of the project project. For example: root_dir/project/.git 
traversal_dir $root_dir 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

[External link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-HJ3YxoCx-1590483913581) (./images/Git: gitPullBatch version-2.0.png)]

  • change itroot_dirvalue can be used

January 3, 2020 version-1.0

git_pull_Batch.sh

#!/bin/bash

#Output git pull xxx and set the font color to green 
function  showMsg ( ) 
 { 
   echo -e " \033 [32m $1 \033 [0m" 
 }

function getdir(){
    for element in `ls $1`
    do  
        dir_or_file=$1"/"$element
        if [ -d $dir_or_file ]
        then
            cd $1"/"$element 
            showMsg 'git pull '$element
            git pull
        else
            echo $dir_or_file
        fi  
    done
}
root_dir="C:\Users\hp\Desktop\qnit"
getdir $root_dir
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

insert image description here

git_pull.sh

#!/bin/bash

echo -e "\033[32mgit pull review\033[0m"
git pull
cmd.exe # prevent the window from closing
  • 1
  • 2
  • 3
  • 4
  • 5
  • This will not be introduced

Related: Git/Shell: batch git pull, one-click update of multiple repositories in the same directory (quickly pull all projects)