You seem to forget that electrons have spins. And that there are two possibilities for the spin : up or down. No other possibilities exist. Now electrons have the tendency to make pairs with one spin up and on down. Sorry for the image, but it looks as if spins up and down represent two different sexes. And that the electron have the tendency to make "couples" of "up" and "down" together, as in the traditional way of being together. On the average, there exist the same amount of electrons "up" and of electrons "down".
Let's take H atoms. Half to the H atoms have spins up, and half down. If you produce somewhere a lot of free H atoms, they will collide. When they have the same spin, nothing happen after the collision. When they have different spins, they will join and stay together, make a covalent bond, which makes a H2 molecule, after the collision. After a while all H atoms are groups in H2 molecules
In the next atom, Helium, there are two electrons on the first layer. They are of opposite spins and Helium will not join with any other atom, and not produce any molecule.
For heavier atoms, form Li to Ne, there is enough room for 8 electrons. The first four have the same spin. The next four have the opposite spin. Hopefully you may understand your self that Li makes LiH, Be makes BeH2, etc. But Oxygen has 6 electrons, 4 of a given spin and 2 of the opposite spin. In Oxygen, there are two doublets which cannot form covalent bonds. Only 2 can do it.
I will not develop this theory too long. You may do it your self. It is not too difficult to do it.