Alkaline earth metals show by losing electrons.
Example: Magnesium atom has 12 electrons in it that are arranged in different shells as 2,8,2. There are two electrons in the outermost shell, so it loses these 2 electrons and forms ion.
Alkaline earth metals show bivalency by losing two electrons.