$ ./guess_the_languageGit
Git · medium · #9

Which command keeps these two new commits safely on a branch?

$ git checkout v1.2
You are in 'detached HEAD' state.
$ git commit -am "fix"
$ git commit -am "tests"
  1. git switch -c fix-v1.2
  2. git reset --hard v1.2
  3. git restore --source v1.2
  4. git switch main
Creating a branch at the current detached commit gives the new commits a name. Switching away first would leave them reachable only through the reflog.
Play Git ▸