If not yet committed anywhere (git status
shows a bunch of stuff modified, it's OK if it's "git add"-ed too):
$ git checkout -b newbranch
Despite the name checkout
this usage (with -b
) does not check anything out. The -b
flag says "create a new branch", so git creates the branch-name and makes it correspond to the current HEAD
commit. Then it makes HEAD
point to the new branch, and stops there.
Your next commit is therefore on newbranch
, which has as its parent commit, the commit you were on when you started modifying files. So assuming you were on master
, and you had these commits:
A - B - C <-- HEAD=master
the checkout -b
makes this read:
A - B - C <-- master, HEAD=newbranch
and a later commit adds a new commit D
:
A - B - C <-- master
\
D <-- newbranch