This is a subject of active research. All the cells in the zygote are identical up to 8 cell stage. At the next division resulting in 16 cells formation it is called a morula.
The zygote has totipotent cells meaning each cell has the ability to develop into full organism by itself if it separates from the zygote (this is how identical twins are born).
Human zygotes are totipotent till at least 4 cell stage. In other primates experiments have demonstrated totipotency upto 16 cell stage.
The totipotent cells differentiate into pluripotent cells and then into various distinct cells belonging to different systems. This process is very complex and a lot of embryological factors and chemicals come into play.
The embryonic factors cause migration (called embryotaxis) and differentiation of the embryonic cells. Some of the factors are sonic hedgehog, wnt, insulin like growth factors, Hox, etc...
Different factors cause differentiation into different cell lines. These factors also cause the organs to attain specific shape and structure, thus the heart is shaped as a heart and the liver is shaped as a liver and so on.
Once the cells differentiate into a particular line, the stem cells of that region generally differentiate into that particular line due to the paracrine influence in that locus, even though these stem cells can differentiate into other cell lines when appropriately stimulated (thus demonstrating pluripotency). So intestinal stem cells would differentiate into goblet cells, surface epithelial cells, Enterochromaffin cells, etc... which are present in that locus.
For more see here: