The 1-inch line was ruptured shortly after 10 a.m. at Pier 15, near The Embarcadero and Green Street.
San Francisco Water Department crews were installing the hydrant when someone using a backhoe struck the gas line, SFPUC spokeswoman Alison Kastama said.
Pier 15 was evacuated as a precaution, and The Embarcadero was shut down between Broadway and Green Street, fire department spokeswoman Mindy Talmadge said.
PG&E crews responded and capped the leak at 10:42 a.m., PG&E spokesman Joe Molica said.
Shortly before noon, Kastama said the evacuation order had been lifted and all but one northbound lane of The Embarcadero had been reopened.