Reputation: 53
$ git checkout -B test
$ # change anything
$ git branch
$ master
$ * test
$ git commit -am 'updated'
$ git checkout master
$ git branch
$ * master
$ test
$ git branch -D test
$ git branch
$ * master
$ git checkout test
$ git branch
$ master
$ * test
why no error? like error: pathspec 'test' did not match any file(s) known to git
Upvotes: 0
Views: 73
Reputation: 94397
From
$ git branch -D test
$ git branch
$ * master
we can see the branch was deleted. The next command
$ git checkout test
recreates the branch from remote-tracking ref origin/test
. See the docs on git checkout
:
If
<branch>
is not found but there does exist a tracking branch in exactly one remote (call it<remote>
) with a matching name, treat as equivalent to$ git checkout -b <branch> --track <remote>/<branch>
Upvotes: 3