I turn now to discussion of the theory of the GRB and the prompt emission. It is generally accepted that both the GRB and the afterglow arise due to dissipation of the kinetic energy of the relativistic flow. The relativistic motion can be dissipated by either external [184, 234, 333] or internal shocks [276, 289, 334]. The first involve slowing down by the external medium surrounding the burst. This would be the analogue of a supernova remnant in which the ejecta is slowed down by the surrounding ISM. Like in SNRs external shocks can dissipate all the kinetic energy of the relativistic flow. On the other hand internal shocks are shocks within the flow itself. These take place when faster moving matter takes over a slower moving shell.
Sari and Piran  have shown that external shocks cannot produce variable bursts (see also Fenimore et al. ). By variable I mean here, following  that t << T, where T is the overall duration of the burst (e.g. T90) and t is the duration of a typical pulse (see Section IIA2). As most GRBs are variable Sari and Piran  concluded that most GRBs are produced by internal shocks . Internal shocks can dissipate only a fraction of the kinetic energy. Therefore, they must be accompanied by external shocks that follow and dissipate the remaining energy. This leads to the internal-external shocks scenario . GRBs are produced by internal shocks within a relativistic flow. Subsequent external shocks between the flow and the circum-burst medium produce a smooth long lasting emission - the afterglow. Various observations (see Section IIA6) support this picture. I begin with the discussion with a comparison of internal vs. external shocks. I review then the prompt emission from internal shocks, then the prompt emission from external shocks (which includes contributions to the late part of long GRBs and the prompt optical flash). I also discuss the transition from the observations of one shock to the other.