A federal judge in San Francisco has ruled that the government may no longer bar an alien from entering the country simply because he is a homosexual.

U.S. District Court Judge Robert Aguilar made the ruling Thursday in a case involving Carl Hill of Great Britain, who was barred from entering the country in 1979 because he was wearing a T-shirt proclaiming his homosexuality.

Aguilar said from the bench that the Immigration and Naturalization Service cannot exclude a homosexual from the country unless a Public Health Service doctor certifies that the person is a "psychopathic personality," one of the exclusions allowed by the 1952 federal immigration law, gay rights attorney Don Knutson said.

In 1979, U.S. Surgeon General Jules Richmond decided that homosexuality would no longer be considered a medical disorder, but INS continued to bar homosexuals who advertised their sexual preferences.

Knutson hailed the ruling as a landmark decision. An INS spokesman said no decision has been made on whether the government will appeal the case.

The issue has political overtones. The 1980 Democratic platform contained a pledge to ban that section of the law, and the Carter administration backed legislation to do so. Since Reagan took office, no similar legislation has been introduced.

Knutson said that Justice Department officials under Carter welcomed the Hill test case, but that the Reagan administration has fought it. "They have raised every possible procedural obstruction," he said.

An aide to Rep. Henry A. Waxman (D-Calif.) said yesterday that there is some concern that the administration may attempt to reverse Richmond's 1979 decision that homosexuality is not a medical disorder.

"In the face of real problems of health care . . . any diversion of valuable Public Health Service time and expertise to a return of political psychiatry would be public malpractice," Waxman said in a statement.

Larry Bush, Washington editor of a national homosexual newspaper, said yesterday that INS records showed that in an eight-month period in 1979 and 1980 few aliens were turned back at major ports of entry because of homosexuality.

Most of about 160 exclusions, he said, occurred in small towns on the Canadian border. He said that more than 40 of those occurred in a small Vermont town where one border guard apparently challenged and excluded homosexual entrants.