It can be through electrolysis, but it is almost never done that way. It's less efficient than simply using the grid to charge batteries, in that usecase the ONLY benefit it has its energy density (and that might not last either).
In practice the main source is as a byproduct from refining fossil fuel like oil or gas which is separated and collected.
Hydrogen is simply less efficient. Switching to it would increase total load on the grid, even if you try to distribute production then the losses takes away available energy for other uses. At some point it becomes cheaper to invest to connect the grid together.