Yes, it does matter, because some brands contain more detergent additives that can prevent carbon deposits from forming inside your engine.
These are the so-called Top Tier brands that use considerably more detergent and/or additives than is required by the EPA. Several vehicle manufacturers recommend using Top Tier gasoline so they and their dealers don't receive complaints from owners about poor engine performance or fuel economy caused by carbon deposits, fouled fuel injectors or other issues.
Most major oil companies have adopted the voluntary Top Tier standards for detergent additives, including Shell, ExxonMobil, BP, Chevron, Phillips 66, Texaco and Valero, among others.
The vehicle manufacturers claim that using other brands of gas over time can allow carbon deposits to form in combustion chambers, which can cause engine knock or pinging (premature fuel ignition), and on intake valves, which can impede valve operation.
This doesn't mean you should never use anything except Top Tier gasoline.
As a practical matter, the smaller, independent gasoline brands and gas stations are often cheaper than the major brands, and for people on a tight budget, saving pennies per gallon matters. Additionally, for some motorists, the nearest Top Tier station may be miles away, making it impractical to fill up at those gas stations consistently. And if you're on an interstate highway and your tank is nearly empty, you have to take whatever gasoline you can get.
Some vehicle manufacturers, such as Hyundai and Kia, suggest that owners who don't use Top Tier gasoline add a fuel-system cleaner to their tank periodically to clean out any deposits or gunk. You should first check your owner's manual to see what the manufacturer says about Top Tier gas, gasoline and octane ratings as well as fuel additives.
Using gasoline from a Top Tier company such as Chevron or Shell as often as is practical and economically feasible, plus periodically adding a high-quality fuel system cleaner if you often use other brands of gas, should do the trick.