Created
January 9, 2023 07:48
-
-
Save sasasin/cc3714028dc983d590cb27c78b801282 to your computer and use it in GitHub Desktop.
カレントディレクトリの全ディレクトリに git pull するやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -eo pipefail | |
| # カレントディレクトリの全ディレクトリに git pull するやつ | |
| function git-pull-force-default-branch () { | |
| cd "$1" | |
| DEFAULT_BRANCH=$( | |
| git remote show origin \ | |
| | grep 'HEAD branch' \ | |
| | awk '{print $NF}' | |
| ) | |
| git fetch origin "${DEFAULT_BRANCH}" | |
| git reset --hard origin/"${DEFAULT_BRANCH}" | |
| echo "$1 $(git symbolic-ref --short HEAD) $(git pull)" | |
| } | |
| # bash function を xargs から呼べるようにする | |
| export -f git-pull-force-default-branch | |
| # カレントディレクトリそのものは除外して | |
| find "$(pwd)" -type d -maxdepth 1 \ | |
| | grep -vE "$(pwd)"'$' \ | |
| | sort \ | |
| | xargs -IXXXX -P5 -n1 bash -c "git-pull-force-default-branch XXXX" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment