Removing YUM repositories from RHEL-family distros

One might accidentally add a repository in YUM (for an RHEL-family Linux distro), which causes errors whenever you try to use YUM. An example error would be:

Error: Cannot retrieve repository metadata (repomd.xml) for repository: foo. Please verify its path and try again

Where “foo” is the name of the repository causing problems.

The following segment was tested in Scientific Linux 6.2. Taking the usual precautions as a prerequisite (backing up your system…), check to see if the repo RPM package is listed by

rpm -qa |grep -i foo

Which will respond with the name of the matching RPMs–if one of them matches the repo you want to get rid of, after having backed up your system, this Terminal command would remove that repo

rpm -e foo