Great question — answering as the UphillTech team:
Possible, yes,* (*with a code violation and resulting fire hazard) meets code, hell no. You can hook up all sorts of bad ideas, but you should not , particularly if you like your garage/house un-burnt. 8AWG copper or 6AWG aluminum. Just for the heater. If you are saying the whole garage is fed by 10AWG, then the feed breaker from the house is limited to 30A maximum until/unless you change that wire. So unless you are already running a violation and hazard on feeding the garage, installing a 40A breaker for a heater at the garage will cause the feed to trip. And if you are running a violation and hazard on that feeder, you'll have things overheating and possibly catching fire. Side note -...
Full answer by Ecnerwal: https://diy.stackexchange.com/a/333494 (CC BY-SA 4.0).
Need it done for your business? UphillTech.