Hacker News new | ask | show | jobs
by nodesocket 4869 days ago
What is the difference between doing:

     git checkout -b bugFix
     git commit
     git checkout master
     git commit
     git merge bugFix master
And

     git branch bugFix
     git commit
     git checkout master
     git commit
     git merge bugFix master
2 comments

git checkout -b bugFix creates the branch and puts you on that branch, git branch bugFix creates the branch and leaves you where you are, so in your first example you are committing on the branch and then merging to master, in the second example you are always committing to master.

try it in the website and you’ll see that in the second case bugFix never changes. the merge will say nothing needs to be done because bugFix already contains all changesets in master.

Creating a branch with

  git branch bugFix
does not automatically check it out, so you'd have to follow it up with

  git checkout bugFix
but if you do

  git checkout -b bugFix
it will create the branch and then check it out all in one step.
Yep! Exactly. The status of the current branch your on is designated by the asterisk (like in real git), but in retrospect I guess it could be a bit more clear...
Yup, makes sense. Thanks.