def getRemote(repo, urls, create=None):
  """Get the remote matching a URL.

  :param repo:
    repository instance from which to obtain the remote.
  :type repo:
    :class:`git.Repo <git:git.repo.base.Repo>`
  :param urls:
    A URL or list of URL's of the remote to obtain.
  :type urls:
    :class:`str` or sequence of :class:`str`
  :param create:
    What to name the remote when creating it, if it doesn't exist.
  :type create: :class:`basestring` or ``None``

  :returns:
    A matching or newly created :class:`git.Remote <git:git.remote.Remote>`, or
    ``None`` if no such remote exists.

  :raises:
    :exc:`~exceptions.Exception` if, when trying to create a remote, a remote
    with the specified name already exists.

  This attempts to find a git remote of the specified repository whose upstream
  URL matches (one of) ``urls``. If no such remote exists and ``create`` is not
  ``None``, a new remote named ``create`` will be created using the first URL
  of ``urls``.
  """

  urls = list(urls)

  for remote in repo.remotes:
    if remote.url in urls:
      return remote

  if create is not None:
    if not isinstance(create, str):
      raise TypeError("name of remote to create must be a string")

    if hasattr(repo.remotes, create):
      raise Exception("cannot create remote '%s':"
                      " a remote with that name already exists" % create)

    return repo.create_remote(create, urls[0])

  return None