Skip to content

Instantly share code, notes, and snippets.

@sasasin
Created January 9, 2023 07:48
Show Gist options
  • Save sasasin/cc3714028dc983d590cb27c78b801282 to your computer and use it in GitHub Desktop.
Save sasasin/cc3714028dc983d590cb27c78b801282 to your computer and use it in GitHub Desktop.
カレントディレクトリの全ディレクトリに git pull するやつ
#!/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