Life with teacher Lemon.

Git 自动化更新本地代码脚本

2020.07.21 | 共 141 字,阅读需约 1 分钟.

在本地开发的过程中,每天需要更新多个项目且大量的 MR 到本地代码库,使用该脚本自动化更新。

#!/bin/bash

echo "---------------------------------------update code start---------------------------------------"

echo "Your code root dir is $1."

# shellcheck disable=SC2006
filelist=`ls $1`

for file in $filelist
do
  if [ -d "$1/$file" ]; then
    echo "update $1/$file start.............................................................."
    # shellcheck disable=SC2164
    cd "$1/$file"
    echo "reset to HEAD.........................."
    git reset --hard HEAD
    echo "fetch all.............................."
    git fetch --all
    echo "pull all..............................."
    git pull --all
    cd ../
    echo  "update $1/$file finish.............................................................."
    echo ""
    echo ""
  fi
done

echo "---------------------------------------update code finish--------------------------------------"
  • 用法:sh updatecode.sh your_code_dir
  • 备注:Windows 请在 Git Bash 中运行.
发表评论
今日诗词