SHANGHAI — Cars should run on gasoline for a little while longer.

So argued Mary Barra, the chief executive of General Motors, who on Friday cautioned against the growing trend of officials in China and a number of other countries making plans to phase out sales of gasoline- and diesel-powered cars.

Speaking in Shanghai on Friday, Ms. Barra said her company was making a big push to develop electric cars but that consumers, not government dictates, should decide how cars are powered.

“I think it works best when, instead of mandating, customers are choosing the technology that meets their needs,” she said.

China this month joined other countries, including Britain and France, to say they will eventually ban sales of gasoline- and diesel-powered cars. Unlike those two countries, which said that they hope to halt sales in 2040, China has not set a date. Other countries, notably India, have been setting similar goals without giving them regulatory force.