diff -r 3bd8ab4c80a5 -r e5b6ba786d83 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Sun Oct 15 23:08:45 2017 +0530 +++ b/mercurial/cmdutil.py Fri Jan 19 18:45:20 2018 +0530 @@ -727,6 +727,11 @@ if len(roots) > 1: raise error.Abort(_("cannot change branch of non-linear revisions")) rewriteutil.precheck(repo, revs, 'change branch of') + + root = repo[roots.first()] + if not root.p1().branch() == label and label in repo.branchmap(): + raise error.Abort(_("a branch of the same name already exists")) + if repo.revs('merge() and %ld', revs): raise error.Abort(_("cannot change branch of a merge commit")) if repo.revs('obsolete() and %ld', revs):