def _get_exist_branches(branch_names, all_branch_names):
    """Filter out not existing branches from branch names or return all branches."""
    if not branch_names:
        return all_branch_names
    return set(branch_names).intersection(all_branch_names)