git - Why checkout -b does work only after second attempt? -


$sudo git clone sample.git   cloning 'sample'... warning: appear have cloned empty repository. done.  $ cd sample  $ echo "hello world" > readme  $ git add readme  $ git checkout -b switched new branch 'a'  $ git branch  $ git checkout master error: pathspec 'master' did not match file(s) known git.  $ git checkout error: pathspec 'a' did not match file(s) known git.  $ git checkout -b b switched new branch 'b'  $ git branch  $ git commit -am . [b (root-commit) 12b8434] .  1 file changed, 1 insertion(+)  create mode 100644 go  $ git branch * b  $ git checkout error: pathspec 'a' did not match file(s) known git.  $ git checkout -b switched new branch 'a'  $ git branch *   b 

what wrong first checkout -b a, why branch not created?

well, told git create branch in empty repository. there no commit yet, , branch "sticky note" pointing commit. git supposed do...

at least stores new branch in head, branch tip updated future commits. shown commit.

more fun empty repositories:

~/tmp> mkdir empty ~/tmp> cd empty ~/tmp/empty> git init initialized empty git repository in tmp/empty/.git/ ~/tmp/empty> git log fatal: bad default revision 'head' ~/tmp/empty> git branch xxx fatal: not valid object name: 'master'. ~/tmp/empty> git checkout -b xxx switched new branch 'xxx' ~/tmp/empty> git log fatal: bad default revision 'head' ~/tmp/empty> ls -l .git/ branches/    config       description  head         hooks/       info/        objects/     refs/ ~/tmp/empty> cat .git/head ref: refs/heads/xxx ~/tmp/empty> ls -l .git/refs/heads total 0 

edit: adopted comment @jthill.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -