I’ve tried a few different options over the years.
I mounted arris rail to my garage wall (cut 45deg timber), and screwed hooks into those so the bikes would sit vertically, back wheel on the floor and front wheel contained by the hook.
I measured it all up beforehand, but it still was a bit of a surprise how far out, into the garage the bikes protruded – even when sitting at a 45deg angle.
I put up with it for a while, before getting so fed up with bumping into them that I ditched the whole set-up & now just have two leaning against the wall top-to-tail & two on a rack the wall – bit of a pain as the arms of the rack aren’t really long enough to hold the bikes well.
I have considered some kind of rolling rail system so you could push bikes up tight to each other when not in use and allow them to rotate out of the way.
Seeing the link that ogg provided above to rollingcenter, I have just had a look & that seems like some very reasonable product. A section of rail, with 5 brackets & carriages looks to be only around £110 or so; then a bit more on top for hooks to hang the bikes on. Tempted to give that a go.