新しいブランチ feature を作って、そのまま切り替えるコマンドは?
正答
- git branch feature
- git switch feature
- git switch -c feature
- git checkout feature
解説
git switch -c feature は新しいブランチを作成して切り替える(古い書き方は git checkout -b feature)。git branch feature はブランチを作るだけで現在のブランチは変わらない。git switch feature や git checkout feature は既存ブランチへの切り替えなので、feature が無ければ invalid reference になる。Git 2.23 以降は checkout の役割が switch(ブランチ)と restore(ファイル)に分かれた。
参考: git-scm.com
この問題を含む Git のテストを制限時間つきで解く
Gitクイズへ