0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

個人的備忘録:error: pathspec 'develop' did not match が出たときの対応メモを整理してみた

Posted at

はじめに

Git を使ってチーム開発をしていると、「リモートにはたくさんブランチがあるのに、ローカルで develop ブランチが見つからない・作業できない」といった状況に出くわすことがあります。

個人の備忘録程度の走り書きとなっておりますが、温かい目で見守っていただければ幸いです。

この記事では、その理由と解決方法について解説します。

書こうと思ったきっかけ

実際に開発現場で Git を使っていて、main 以外のブランチがローカルに表示されず戸惑うケースがありました。特に develop ブランチが見えないときの対処方法を整理するためにこの記事をまとめました。

なぜローカルで develop ブランチが見えないのか?

Git は、クローンした時点では main ブランチしかローカルブランチとして作成されません。他のブランチ(たとえば develop)は、"リモート追跡ブランチ" として存在するだけで、ローカルにはまだ作成されていないのです。

つまり、ローカルで develop ブランチを作業対象にするには、明示的に取得(fetch)し、チェックアウト(checkout)する必要があります。

解決方法

1. リモートの情報を取得

git fetch origin

2. develop ブランチに切り替える(ローカルにない場合は作成)

git checkout develop

もし以下のようなエラーが出た場合:

error: pathspec 'develop' did not match any file(s) known to git

この場合はリモートの origin/develop を元にローカルに作成します:

git checkout -b develop origin/develop

ブランチ一覧の確認コマンド

git branch        # ローカルブランチ一覧
git branch -r     # リモート追跡ブランチ一覧
git branch -a     # ローカル + リモートすべてのブランチ一覧

まとめ

  • Git は自動で全てのリモートブランチをローカルに作成するわけではない。
  • git fetch + git checkout -b develop origin/develop の手順でローカルに develop ブランチを作成可能。
  • git branch -rgit branch -a を使ってリモートブランチの存在を確認。
0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?