|
|
|
|
|
by bacon_waffle
2169 days ago
|
|
Maybe this depends on your mental model of what a git checkout is? To me, "git checkout X" means: update the working directory to reflect X and update HEAD to point at X. (edit: and HEAD means "the branch to update when a new commit is made"). I use "git checkout" a lot more often than "git branch" and "git checkout -b" combined. So, to me, the fact that X is a to-be-created branch is secondary to the primary "checkout" operation. That said, I do vaguely recall this seeming weird at first. |
|
---Succinct argument---
What happens if you remove the flag? Put differently, how much does the flag change the semantics?
`git branch newbranch` will gracefully fall back to creating a new branch at HEAD.
`git checkout newbranch` will fail (error: pathspec 'newbranch' did not match any file(s) known to git), because the regular version of the command involves operating on something that already exists.
---Less succinct further argument---
checkout's `-B` variant. Here's how the man page explains it:
> If -B is given, <new_branch> is created if it doesn’t exist; otherwise, it is reset. This is the transactional equivalent of > > $ git branch -f <branch> [<start point>] > $ git checkout <branch>
If it were a flag on branch, you wouldn't need a separate flag, just `git branch -fs newbranch` (-s for --switch).
Actually, looking through the man page for `checkout` now, I see 4 other options I didn't know about (-t|--track, --no-track, --guess, --no-guess), apparently for the sole purpose of being used with -b.
---
I don't think I thought of this argument when I originally chatted in #git-devel, maybe I'll give it another try.