The word "example" implies IMHO that there are other possibilities as well.
alternatively, I could imagine a security in the land register.
why? one can simply write something like: I, egon, and all my legal successors agree. i.e. whoever buys from egon buys his consent as well
But the legal successor does not have to care about that, so it is not a legal security (i.e. effective against unspecified third parties). The legal successor has no contract with the original poster. Of course, the neighbor could make that a condition of the sale and have it included in the notarial contract. But even then, he cannot be forced to do so. That would be unfair and possibly liable for damages, but it destroys the legal security of the construction-law-compliant condition of the garage.