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 additives than is required by the EPA. Several vehicle manufacturers recommend using Top Tier gas so they and their dealers don't receive complaints from owners about poor 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 gas.
As a practical matter, the smaller, independent gasoline brands 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 there consistently. And if you're on an interstate highway and your tank is nearly empty, you have to take what you can get.
Some vehicle manufacturers, such as Hyundai and Kia, suggest that owners who don't use Top Tier gas 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 and fuel additives.
Using Top Tier gas as often as is practical and economically feasible, plus periodically adding a fuel system cleaner if you often use other brands of gas, should do the trick.