Last active
October 25, 2021 00:10
-
-
Save udaken/56a68c448a72c497148f4a221d890f8f to your computer and use it in GitHub Desktop.
特定のブランチをgitリポジトリ間でミラーリングするシェルスクリプト
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 -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