-1

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

dineshdileep
  • 715
  • 2
  • 13
  • 24
  • It's worth noting here that branches—or more precisely, branch *names* —have very little value on their own, as all the *files* in some branch are actually stored as snapshots associated with commits. Adding a new branch name does not add a new commit, it just adds another name for some *existing* commit. So you can add all the names you like without making any copies of any files. – torek Jul 03 '19 at 16:34

1 Answers1

0

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.

mnestorov
  • 4,116
  • 2
  • 14
  • 24