LoginSignup
2
1

More than 1 year has passed since last update.

複数リポジトリを一括でgit pullするShellを書いてみた

Last updated at Posted at 2021-06-25

背景

リポジトリを数十個に分割して相互に依存関係があるコードを開発しており、毎日数十個のリポジトリを一つ一つgit pullするのが手間だったので、同一ディレクトリ内にgit cloneしているリポジトリを一括でgit pullするShellを書いてみた。

やったこと

以下のShellを書いた。

git-pull.sh
#!/bin/sh

# 処理したいgitリポジトリ一覧を置いているディレクトリパス+リポジトリ名のプレフィックスを保持する変数dir_pathを定義
dir_path="/path/to/directory/repository-name-prefix*"

# $dir_pathに合致するgitリポジトリのディレクトリをforループで処理
for dir in $dir_path;
do
  (
    # 処理対象のgitリポジトリを表示
    echo $dir
    # gitリポジトリのトップディレクトリへ移動
    cd $dir
    # git pullコマンドでリモートリポジトリの変更を取得
    git pull
  )
done

以下のshellコマンドでも同じことができる。

ls -1 | while read repo; do (cd $repo; echo $repo; git pull); done
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1