Subject: "Branch exists" error while trying to rename a non-existing branch to an existing one

From: Kaartic Sivaraam <[email-masked]>
Date: Sun, 09 Jul 2017 23:57:39 +0530

Hello all,

I recently got the following error message by change as a result of the
command,

    $ git branch -m no-branch master
    fatal: A branch named 'master' already exists.

Note: no-branch is an hypothetical branch that doesn't exist.

Shouldn't I get a 'no-branch' doesn't exist before that? Wouldn't this
behaviour make the users search for the non-existing 'no-branch' in
their repo?

I tried digging the implementation a little and what I could interpret
from it is,

    * only the validity of new branch name (master, in the above case)
    is checked
    * checking for existence of the branch being renamed(no-branch) is
    not done at all. It seems to be left to the lower level commands to
    identify.

I'm puzzled by seeing this. Why isn't there any check for the existence
of the branch being renamed and warning the user about that first?

-- 
Kaartic