git-merge allow-unrelated-histories
--allow-unrelated-histories
オプションを見てみる
By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added.
- 同じ先祖じゃないブランチをマージしようとすると
fatal: refusing to merge unrelated histories
エラーになる- ブランチは通常特定のブランチから派生して作成するけど、最初のコミットが違ってて派生もしていない場合
- 非常にレアケースなので、Gitでこのオプションを変更する設定はないし、実装する予定もない
ので、そういった場合は、 git merge --allow-unrelated-histories
してやるとよい。
GitHubだと、
- GitHubで空のリポジトリを作る
- 空のリポジトリをローカルでcloneする
- GitHub上で、りどみなどのファイルを作成し、コミットする
- ローカルでファイル作成→コミット
- push出来ないし、pullも
fatal: refusing to merge unrelated histories
となる