
投稿日:2022/10/31 最終更新日:2023/11/19
mainブランチでgit pullをするとYour configuration specifies to merge with the ref “ブランチ名” from the remote, but no such ref was fetched.と出てしまいコミットを取得できない時の解決法
mainブランチでgit pullをした際にリモートブランチがorigin/mainになっておらず、最新コミットが取得できないなんてことが起きました。
「Your configuration specifies to merge with the ref “ブランチ名” from the remote, but no such ref was fetched.」と表示されるエラーも見たことが無かったのでよく見てみると別ブランチがmainのリモートブランチになっていました。
ブランチの変更の際に切り替わっていない段階で変にコミットやらプッシュやらをしてしまったことが原因だと思いますが、結構簡単に解消できましたので、お困りの方は参考にしてみてください。
解決法
めちゃくちゃ簡単です。
以下の手順でgitを操作していきましょう。
1. 最新のコミットを取得する
git fetch
最後にgit pullをしますが念のためです。
2. mainブランチのリモートブランチを解除する
git branch --unset-upstream
ココが重要です。
おそらくorigin/mainと本来なっていなければいけない部分が別のリモートブランチに切り替わっているか、上手く接続できていないからなので、一度解除します。
3. mainブランチとorigin/mainを接続する
git branch -u origin/main
ローカルのmainブランチとリモートのorigin/mainを接続します。
4. 最後にgit pullをして確認
git pull
git pullをして「Your configuration specifies to merge with the ref “ブランチ名” from the remote, but no such ref was fetched.」のエラーが出力されず、最新コミットを取得 or「Already up to date.」と表示されればOKです。