Petrogenesis

Petrogenesis, also known as petrogeny, is a branch of petrology dealing with the origin and formation of rocks. While the word petrogenesis is most commonly used to refer to the processes that form igneous rocks, it can also include metamorphic and sedimentary processes, including diagenesis and metamorphic reactions. 
Petrogenesis of an igneous rock comprises three successive stages: magma generation, magma differentiation and assimilation of crust.