Just be aware you will be (indirectly) emitting more CO2, and using more pesticides and fertilizer by buying from Farmers Markets. So you have to decide what's more important to you. (Small farms are less efficient, less efficient means uses more energy and other inputs.)
There is a middle ground between the "processed foods from these mega corporations" (which I agree you should not buy) and farmers markets though: Just buy regular produce from a grocery store, and cook normal food.
I actually think what you eat is the dominating factor in food CO2 production: https://ourworldindata.org/uploads/2020/02/Environmental-imp... Transport and processing are fairly minor components overall for all foods. The claim about pesticides and fertilizers I know nothing about though.
You should buy organic at the farmers' market AND the supermarket, but that's a different topic.
It's definitely not clear to me that farmers' markets are worse for the environment - in many cases, it's the same farmer looking for a direct-to-consumer outlet for some of their product.
Small local farms also don't have to ship the food across the country or the ocean to get it to you. That drastically reduces the carbon footprint of such consumption.
It actually does not. Shipping food emits very very little CO2 compared to growing it.
So the most optimum thing (in terms of CO2) is to plant food where it grows best and then ship it.
As an extreme example compare a greenhouse with regular outdoor planting. Or compare growing food where you need a lot of pesticides or fertilizer vs where you do not.
In case it wasn't clear: It's better to grow food without a greenhouse, then ship it vs. spending energy on a greenhouse, and saving energy on shipping.
The reason is simply that shipping uses very very little energy, it's the rest of the production that uses a massive amount of energy.
Local farms generally consume more carbon to get your goods to you. That's because the ratio of envelope : contents for each subsequent chain in transportation goes up exponentially. eg: It takes ~0.1kg of cargo ship to transport 1kg of food, ~1kg of container truck, ~5kgs of a pickup truck from a local farm and ~100-1000kgs of your personal car, depending on how much you buy per trip.
So buying food from a local farm delivered to you via pickup truck or having a farmer's market that's just a little bit further away from you than a grocery store or buying just a little bit less at the farmers market than you would at a grocery store can negate the entire difference of having foods shipped to you from all across the world.
A truck for locally produced food is not usually full nor efficiently packed.
Rather the farmer will grab a little of this, and a little of that. Whatever he can sell the day. This uses far more energy.
And don't forget the energy needed to harvest the food - large growers do it in bulk, small farmers will need to fire up the tractor for short runs.
A cargo ship uses FAR FAR FAR less energy than you might imagine. Even shipping something by rail across the US uses less energy than driving to the next city.
There is a middle ground between the "processed foods from these mega corporations" (which I agree you should not buy) and farmers markets though: Just buy regular produce from a grocery store, and cook normal food.