To understand how Guy managed to master the Hachimon Tonkou (Eight Gates Release Formation), let us take a look to how jutsus are learned in Narutoverse.
There are 3 ways a jutsu can be learned.
- Learn it from a teacher.
- Learn it from a scroll/book.
- Learn it yourself (a.k.a. invent it).
Learn it from a teacher
This might be the easiest way to learn a jutsu. You have a teacher teach you how to perform a certain jutsu. Most ninja learn jutsu this way through the academy. Example of jutsus learned through this method: Bunshin no Jutsu, Kawarimi no Jutsu, Sasuke learning Chidori from Kakashi, Naruto learning Rasengan from Jiraiya.
Learn it from a scroll/book
This is a method that is harder than the first method. You learn it from a book. I no longer have the copy with me but my father used to have a book that teaches kungfu moves. In that book there are explanations and illustrations on how to perform certain moves. You learn the techniques by performing as the book says. Example of jutsus learned through this method: Naruto learning Kage Bunshin no Jutsu, Orochimaru learning various jutsus using scrolls he stole from the library.
Learn it yourself (a.k.a. invent it)
This method might be the hardest of the 3. You learn the jutsu by creating it yourself. You can invent it through seeing natural phenomena or other people performing a certain jutsu, copy it and change several aspects of it to make your own jutsu using the same principles. Example of jutsus learned through this method: Minato learning Rasengan, Kakashi learning Chidori/Raikiri, Naruto learning Rasen Shuriken, Tobirama learning Kage Bunshi no Jutsu.
How does Guy knows how to perform jutsus in the Hachimon Tonkou?
To answer this we need to identify how Guy learned the jutsu and his training method. Guy learned the jutsu from Might Duy, his father. Guy's training method consists of extreme physical training, such as walking around the village for 500 laps using his hands, thousands sit ups and image training. The image training was mentioned in the manga (and perhaps the anime as well) as one of methods he used to train himself with the reasoning being training his ability to predict enemy movements. Guy also trains by sparring with Kakashi to enhance his fighting senses.
Since Hachimon Tonkou is a taijutsu, let's talk about real life taijutsu training. Taijutsu in real world, such as Kungfu, Karate, Kendo are mastered through training the said moves. A complete newbie can perform Iai Slash, but they would perform it badly as they only copy the movement in general. What differentiates a master from those newbies is that they perform the same move over and over through training until they can use the move with super precision (perfect foot-steps, sword drawing timing, slashing direction, power, speed).
Might Guy might learned the jutsus used in Hachimon Tonkou by learning the moves itself in normal state or 7th gate release state, which is the closest he can get to without killing himself. He learned the jutsu by training the moves over and over in the 7th gate release state while also doing image training since he can't perform the jutsu for real. Combining that with the points I bolded above and fighting sense honed through experience of real combat and sparring with one of the best Shinobi ever (Hatake Kakashi), it is very possible for him to perform the jutsus splendidly despite that being the very first time he used it for real because already mastered the basics to perform that.
It is the same as when you do a chemistry practical test at school despite knowing only the theory (including the steps). Can you do it? Yes, but it might be a bit sloppy since you never do it for real. If you have practiced the movements (pouring the chemicals, measuring it, using the pipette) using a substitute liquid (like water for example) you would be able to perform it greatly even if that was the first time you use the chemicals.