Skip to content

Instantly share code, notes, and snippets.

@udaken
Last active October 25, 2021 00:10
Show Gist options
  • Save udaken/56a68c448a72c497148f4a221d890f8f to your computer and use it in GitHub Desktop.
Save udaken/56a68c448a72c497148f4a221d890f8f to your computer and use it in GitHub Desktop.
特定のブランチをgitリポジトリ間でミラーリングするシェルスクリプト
#!/bin/bash
set -eu
source_repo=origin
dest_repo=old
# リモートからフェッチ
git fetch --prune $source_repo
# チェックアウトしているブランチを更新できなので、分離HEADをチェックアウト
git checkout HEAD
# delete local branches
for branch in $(git for-each-ref --format='%(refname:short)' refs/heads/); do
git branch --delete --force $branch
done
for branch in $(git for-each-ref --format='%(refname:lstrip=3)' refs/remotes/$source_repo/); do
# HEADとfix/*とfeature/*を除いてローカルブランチを作成する
if [[ $branch != "HEAD" && $branch != fix/* && $branch != feature/* ]]; then
git branch --track --force $branch remotes/$source_repo/$branch
fi
done
# ローカルブランチをすべてプッシュ
git.exe push --all --progress $dest_repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment