0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

全ブランチPULLするスクリプト組んでみた

Posted at

概要

Gitリポジトリ移動したりする時に、自分のローカルブランチをすべてPULLするのが面倒だったのでスクリプト組んでみました

環境

OS: Mac OS EI Capitan

スクリプト

git_pull.sh
# !/bin/sh

DIR=("RepoPath1" "RepoPath2")

for GitDir in ${DIR[@]};do

  echo "#################################"
  echo " $GitDir"
  echo "#################################"
  echo

  echo "# cd $GitDir"
  cd $GitDir
  echo 

  echo "# git fetch --all"
  git fetch --all
  echo 

  echo "# git branch -r"
  BRANCH=`git branch -r`
  echo 

  echo "# exec git pull"
  for br in $BRANCH;do
    if [ `echo $br | grep "^origin/" | grep -v "HEAD"` ]; then
      BR=${br:7}
      echo "# $BR"
      git checkout $BR
      git status
      git pull origin $BR
      echo "----------------------------"
      git status
      echo "----------------------------"
      echo 
      echo
      sleep 1
    fi
  done

done

説明

とりあえずリモートブランチの一覧を取得して、そのブランチすべてに対してgit pullしてるだけです。
複数のリポジトリを同時に実行したかったので、対象とするディレクトリを配列で持たせています。

もっといいやり方あると思うので、これのほうがいいよ!というのがあれば教えていただけると助かります。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?