4 ms·
you list, move, rename and delete branches with branch, but create branches using checkout? Seriously??? git checkout -b new-branch ... is a shortcut for:
by damncabbage 14y ago
you list, move, rename and delete branches with branch, but create branches using checkout? Seriously???
git checkout -b new-branch
... is a shortcut for:
git branch new-branch
git checkout new-branch
You can create the branch or otherwise manipulate it without actually checking it out, so it's useful to have it separate and have a shortcut.
(I agree that git's interface is terrible, but I disagree that this is one of those cases. :) )
- sjwright 14y ago> but I disagree that this is one of those cases I do think this is precisely one of those cases. "Branch" is a major, repo-modifying operation; "checkout" is a trivial context switch operation. The user interface disaster here was that the major operation is treated as subservient to the trivial operation. It should be the other way around. Therefore, the shortcut for creating a branch and switching to it should be git branch -c new-branch whereby the -c switch checks you into that branch immediately.
- johnny22 14y agobranches aren't supposed to be "major". That's the major difference between a system like git and svn. branches are cheap. They are supposed to be used often and even be disposable.
- cjh_ 14y agoI don't understand how creating a branch is a major operation. Creating a branch is non-destructive and cheap, tidying up after accidental creation is also easy.
- skybrian 14y agoExcept, why isn't it "git branch --nocheckout" for the rare cases when you don't want to check out?
- nessus42 14y agoWhy doesn't "mkdir" cd you into the new subdir unless you type "mkdir --no-cd my-dir"?
- wookietrader 14y agoHere's why: In 95% of the cases you create a git branch, you check it out. In 95% of the cases you create a directory, you do not cd into it.
- nessus42 14y agoFor me, it's about 50% for each. I often create a branch just to snapshot the current state of the branch before squashing or rebasing. When I do this, I do not checkout the new branch, and in fact, most likely I will never check it out. A common mistake people make when bitching about Git, is assuming that their workflow is the only workflow. Git supports a multitude of different workflows, and that fact is both a strength and a weakness.