The gallon defined in the Magna Carta is 'eight pounds'. Wine for being more dense than wheat, gives a smaller gallon. This gallon was 216 cu inches, using a Mercantile pound of 15 tower ounces, but became larger as larger pounds were used. The wine gallon in troy pounds gives 230.4 cu inches.
The Guildhall representation is 224 cu in, but described as a cylinder seven inches in diameter and six inches high. This gives 230.9 cu inches, but rounded to 231 cu inches.
There were other gallons, such as the beer and ale gallon, which is 282 cu inches, the corn gallon of 268.8025 cu inches, etc. The US uses the corn gallon as the basis of a corn bushel, the bushel being a cylinder 18½ inches in diameter, and eight inches deep.
The USA declared independence in 1776 and won that in 1783. This means that they did not get the reforms of 1820, enacted in the Imperial Weights and Measures Act.
This act abolished all old gallons, and introduced a new gallon, represented by ten pounds of water, at 62°F against brass weights in air. This is the imperial gallon, initially set at 277.274 cu inches, but the 1899 calibration caused it to be 277.420 cu inches.
So the US and UK originally used the same gallon, then we changed ours.