public function branchExists($branchName, $dir = null, $mustRun = false)
    {
        // The porcelain command 'git branch' is less strict about character
        // encoding than (otherwise simpler) plumbing commands such as
        // 'git show-ref'.
        $result = $this->execute(['branch', '--list', '--no-color', '--no-column'], $dir, $mustRun);
        $branches = array_map(function ($line) {
            return trim(ltrim($line, '* '));
        }, explode("\n", $result));

        return in_array($branchName, $branches, true);
    }