1
1

More than 1 year has passed since last update.

mainブランチでgit pull出来ない時の簡単な解決法

Last updated at Posted at 2022-11-12

以前、mainブランチでgit pullをすると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と本来なっていなければいけない部分が 別のリモートブランチに切り替わっているか、上手く接続できていないからgit pullが出来ていない ので、リモートリポジトリとの接続を一度解除します。

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.」のエラーが出力されず、 最新コミットを取得もしくは「Already up to date.」 と表示されればOKです。

まとめ

gitはミスをするとやっかいなので一度まとめてみました。
ココがおかしいなと感じるところがありましたら、コメントにて教えてください。

1
1
0

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
1
1