Do you mean that you record your vocals first? That's an unusual way to do it. If you are more conventional, and doing the instrumental first, it's pretty easy.
You need a full-duplex interface (USB, sound card, or whatever) so you can route the playback of the the guitar to your headphones while you record the vocal track.
Make sure you're not routing the playback track to the new recorded track (see this sticky
https://homerecording.com/bbs/showthread.php?t=117692 for the cure).
If your gear does not allow word clock synch, go to Options/Devices/Settings/Multitrack tab and find the boxes that say "Correct for drift in Recording" and "Correct for start drift in Recording" and make sure they are ticked.
If you are using a setup where the soundcard is synched to a master, you don't need to do that last step.
Once you have recorded the vocals, you should have two tracks that play back together.
If your question is about how to play your guitar in synch to a previously recorded vocal, the answer is practice, practice, practice.