Hi Dal, actually all of us have the same genes.
The thing that makes us unique is the version of the gene, there are slight mutations from person to person which change some of the characteristics, which makes us different.
The cells of our bodies are able to recognize which cells our ours and which ones are foreign (invaders). An organ that is transplanted is thus also recognized as foreign, UNLESS it is from a family member (rejection rates in that case are lower).
Doctors actually have to force a body to accept a foreign organ, they do this by surpressing the immune system (which acts to recognize foreign things and attack it). They have to give very large doses in the beginning, but this also leads to infections. Thus slowly they start to lower the dose and hope that all goes well.
It DOES mean that someone with a transplant will have to be on immuno supressant therapy for the rest of its life.