LoginSignup
30
17

More than 3 years have passed since last update.

gitでどうしてもリモートのブランチがcheckoutできないとき

Last updated at Posted at 2019-06-19

fetchしていないとかそういう話ではない。

>git checkout [ブランチ名]
error: pathspec '[ブランチ名]' did not match any file(s) known to git.

かなり古いディレクトリ(サイズが大きいので再cloneしたくなかった)の上に色々弄ったので条件が確かでないが、恐らく下の操作で解決した。

> git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
> git fetch origin
> git checkout [ブランチ名]

参考:https://stackoverflow.com/questions/35235232/check-out-a-branch-that-exists-in-a-remote

追記

single-branchでcloneした(shallow cloneの場合などデフォルトでそうなっている)リポジトリだとremote.origin.fetchにそのブランチしか設定されず、この様にfetchしても虚無という事になるようだ。

30
17
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
30
17