This is known as the “Flehmen sequence”, where the male giraffe will approach the female and then rub against her backside until she pees. When/if she does, he’ll taste it to tell whether she’s in heat or not. If she is, he will then proceed to stalk her, with the female sometimes continually walking or running away from him. During this time, he will attempt to keep other males away from the female as he pursues her, which is often the point of the female’s rejection, trying to see if she can get a better male to become interested in her and fight off the current male.
Somewhat bizarrely, at least from a Darwinian perspective, after a necking battle, the males will often caress one another with their necks (which is sometimes misinterpreted as fighting) and then have sex with each other, including reaching climax. In fact, it’s estimated that 75% to 94% of the time male giraffes have sex, it is with another male giraffe.