Question: how did damon come back to life?
Answer: After doing some magic under an eclipse, Bonnie sacrifices herself in order to push Damon into being into the real world in Season Six Episode Five. Thus, Damon is alive and well at the end of episode five and hugs Stefan.