Brookline and Watertown last week became the first communities in the state to adopt a new building code discouraging the use of fossil fuels in new buildings, and 22 more cities and towns have signaled they intend to take similar action, in what climate advocates say is the first large-scale test of Massachusetts’ willingness to wean itself from gas and oil.

The new code, finalized by the state Department of Energy Resources last month, adds new requirements to the current building codes in communities that choose to adopt it. It stops short of being an outright ban of fossil fuel heat, but by requiring stringent energy efficiency measures and add-ons like solar panels in buildings that plan to install gas line connections, it is likely to sharply curtail it.

Even some of the most staunch supporters of the electrification movement have some concerns about the new code. Kyle Murray, the Massachusetts program director for the clean energy advocacy group Acadia Center, said that some additional measures may be needed to ensure low income residents are not negatively impacted, though he noted that on the whole, things are moving in the right direction.

“Cities and towns are leading the way, and I think we’re going to see a sort of point where — I don’t want to use disaster metaphors — but there’s a dam breaking,” Murray said. “We’re going to see these cities and towns do it and then we’re going to see so many more cities and towns say, ‘Oh, yeah, we can do this too.’ ”