As far as I know, it is the case that a different subsequent neighbor would no longer have to tolerate this garage, even if you come to an agreement with the current neighbor – but I am not an expert on this. Our garage partially stands on the neighbor’s property, and for that they were given a piece of our property to use back then; this agreement was made between the previous owner of our house and the current neighbors. We took it over and left it as it was, but we could have also dissolved the agreement. However, if the owners over there were to change, they could insist on reversing this agreement. Then we would have to dismantle the garage and they would have to give us back our garden piece. There is no construction burden registered in our case, only a note about this matter was included in the purchase contract.
The situation is similar with trees that are unlawfully large and stand too close to the fence. Here too, a new neighbor can demand that the tree be removed. For example, our neighbors have a huge thuja (as tall as our house, and we have two upper floors), which stands almost directly on the boundary. We could have demanded its felling within a certain period (we did not do so and do not intend to).
I think this is a factor not to be underestimated, for which one should seek advice. If that really applies, then in your place, I would simply build the garage correctly from the start and thus avoid possible trouble in the future.