Git4 択難易度 基礎

新しいブランチ feature を作って、そのまま切り替えるコマンドは?

正答

  1. git branch feature
  2. git switch feature
  3. git switch -c feature
  4. 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

branchswitchcheckout

この問題を含む Git のテストを制限時間つきで解く

Gitクイズへ