git clone --mirrorについて調べてみた
Gitリポジトリを移行する際にgit clone --mirror
コマンドを使いました。
既存のGitリポジトリをAWS CodeCommitへ移行する - 言語化の練習
本来よくありませんが、上記コマンドの意味を正確に理解せずに、AWSのユーザーガイドに従ってコマンドを実行しました。
意味を理解せずにコマンドやコードを引用することは危険なので、事後ではありますが調べてみました。
以下、公式ドキュメントより引用
Git - git-clone Documentation
--mirror
Set up a mirror of the source repository. This implies --bare. Compared to --bare, --mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.
Google翻訳を元に意訳
ソースリポジトリのミラーをセットアップします。 これは --bare を意味します。 --bareと比較して、--mirrorは、ソースのローカルブランチをターゲットのローカルブランチにマップするだけでなく、すべてのリファレンス(リモート追跡ブランチ、notesなどを含む)をマップし、 refspec設定をセットアップして、これらのすべてのリファレンス ターゲットリポジトリ内のgit remote updateによって上書きされます。
bareリポジトリ
はワークスペースが存在しない更新管理用のリポジトリ。
bareリポジトリだと追跡ブランチの情報などが残らない。
Gitリポジトリの移行をする際はコメントやブランチの遷移を残しておきたいので、mirrorリポジトリを移行する。