By either gaining or losing an electron.
So for the halogens (group 17) they have 7 valence electrons so they need one more to have a full outer shell. They will form a bond with another element that can give an electron. Typically a halogen will bond with an alkaline metal because they have 1 valence electron in their outer shells. This sharing of electrons (covalent bond) satisfies both elements, giving them full outer shells.