Let's say "dev" is a branch I have and "myfeature" is something additional I want to work on top of "dev". What is the difference between the commands
$ git checkout -b myfeature dev
and
$ git branch -c dev myfeature
Let's say "dev" is a branch I have and "myfeature" is something additional I want to work on top of "dev". What is the difference between the commands
$ git checkout -b myfeature dev
and
$ git branch -c dev myfeature
Per this answer (and where I am taking the info from), we can see that the difference is that a branch and its reflog and configuration is copied to the new branch when using the -c
option (it is not moved).
This is useful for e.g. copying a topic branch to a new version, e.g. work to work-2 after submitting the work topic to the list, while preserving all the tracking info and other configuration that goes with the branch, and unlike --move
keeping the other already-submitted branch around for reference. After the copy, you do not go to the new brach, i.e. stay at the point where you made the copy.
When creating a new branch B
by copying the branch A
that happens to be the current branch, it also updates HEAD
to point at the new branch.
There is a nice metaphore to see the difference:
If I were sitting on a blue chair, and somebody comes and repaints it to red, I would accept ending up sitting on a chair that is now red (I am also OK to stand, instead, as there no longer is my favourite blue chair).
But if somebody creates a new red chair, modelling it after the blue chair I am sitting on, I do not expect to be booted off of the blue chair and ending up on sitting on the new red one.