0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【エラー】GitでPullできない現象が発生したときの対処方法

Last updated at Posted at 2025-06-26

以下のようなエラーに遭遇

Git Pullしても全くリモートブランチから取得できずpushもできない状態でフラストレーションだけがたまっていました。現象はGitlabでReadme.mdの入ったプロジェクトを作った後にそのReadme.mdをローカル環境でpullできないという現象でした。

 * branch            main       -> FETCH_HEAD
fatal: refusing to merge unrelated histories

そんな時は上記のunrelated historiesを気にしないように伝える必要があるようです。

pushするときに以下のオプションを入れましょう

git pull origin main --allow-unrelated-histories

その後指摘を受け以下の方法がいいとなりました!
@gyokutoさん情報ありがとうございます!

git fetch する (= origin/master が更新)
ローカルの master を、git rebase -i --root --onto origin/master で、origin/master 上に 再構成する
更新した master を git push
みたいな手順になるんじゃないでしょうか?
rebaseすることで、リモート側のコミット (= origin/master) のほうの系譜に 構成し直しています。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?