LoginSignup
0
0

More than 1 year has passed since last update.

Gitのリモートブランチをローカルでcheckoutしたときのエラー

Last updated at Posted at 2021-10-17

はじめに

リモートにあるブランチを使って開発をするために、ローカルに持ってくる方法

目次

  1. メインのコマンド
  2. エラー
  3. コメント
  4. 参考文献

1. メインのコマンド

既にローカルにリモートブランチの情報をfetchできていれば、このコマンドだけでリモートのブランチをローカルでcheckoutできる

git checkout -b local-branch origin/remote-branch

local-branch は自分がローカルで使う任意のブランチの名前でOK
remove-branch はローカルに持ってきたいリモートブランチの名前

2. エラー

fatal: 'origin/somebranch' is not a commit and a branch 'somebranch' cannot be created from it

もしこのエラーが発生したら、ローカルにリモートブランチの情報をfetchできていない
リモートブランチの情報をローカルにfetchするコマンド

git fetch origin remote-branch

fetchコマンドを実行したらもう一度

git checkout -b local-branch origin/remote-branch

3. コメント

リモートのブランチの情報をローカルにfetchするときに、以下のコマンドで全てのリモートブランチの情報をfetchできるはずが、何故かできなかったのでリモートブランチ名を明示してfetchしたらcheckoutできた

git fetch

4. 参考文献

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