def _handle_remotes(config, only_remotes, add_remotes, remove_remotes):
    """ Manages remotes.
    """
    if only_remotes is not None:
        for remote in config.remotes:
            config.remove_remote(remote.host, remote.port)
        for remote in only_remotes:
            config.set_remote(remote.host, remote.port, remote.tls)
    else:
        for remote in add_remotes:
            config.set_remote(remote.host, remote.port, remote.tls)
        for remote in remove_remotes:
            config.remove_remote(remote.host, remote.port)
