Why according to Hund's first rule all electron with same spin should occupy orbitals when partially filling? I get that because of coulomb repulsion initially all the electrons will not occupy the same site but will single occupy the orbitals.But while doing so how do they know to keep their spins aligned along the same direction? either all up or all down? I read somewhere that by keeping their spins aligned along the same direction they are more shielded from nuclear attraction.But I wonder if that's the only explanation and if its correct.
 A: To have the right picture in mind, you need to also take into account the Pauli exclusion between the electrons, being fermions, but also more importantly, do not exclude the nucleus from the picture here!  
Now, Why rule one holds you may ask? Well it clearly cannot be due to dipole dipole interaction between electrons as it's so insanely small (let's say with dipole moment being a Bohr magneton, in an atom), that it will remain irrelevant for our discussion here.
But as you say, it is largely due to Coulomb interaction, but that's not the whole story. Lets take a system of two electrons (1 and 2), associated with the wavefunction $\psi$, which will be composed of an orbital part $\phi$ and a spin part $\xi$: $$\psi=\phi_{orb}(\mathbf{r}_1,\mathbf{r}_2)\xi_{spin}(1,2)$$
The above should be anti-symmetric as we're dealing with fermions, this in mind: 


*

*If the spins are both up, the $\xi$ is symmetric, so $\phi_{orb}$ has to be anti-symmetric, which means that when $r_1=r_2$, $\phi$ has to go through $0.$ (antisymmetric functions). This in turn implies that the electrons cannot get close to each other. This line of reasoning may work, by leading to arguments solely in the line of Coulomb interaction between electrons $V_{ee}$, but that's not entirely correct.


The correct and complete answer is as follows (will try to make as intuitive as I can): 


*

*The key to the answer lies in the $V_{ne}$ term, i.e. the coulomb interaction between nuleus-electron. 

*First case: if the electrons have opposite spins, then they're allowed to get close to each other, and this means that the one closer to the nucleus will now screen the other electron from the nucleus and meaning the electron bit further away will experience a smaller effective nuclear charge, which results in this electron being weakly bound, not favorable! 

*Second case: Now if their spins are aligned, due to Pauli exclusion principle, they cannot get as close to each as before, in particular neither of the electrons can get inside the other one's orbit, hence no more screening effect on the nucleus! Consequently we say both electrons here are strongly bound, favorable! Because it means the overall energy is lowered by having both electrons' spins aligned. Hund's first rule! 

*In short: When the spins are anti-aligned, sometimes one electron will get in between the other electron and nucleus, hence screens the effective charge of the nucleus. But when they have their spins aligned, they repel each other due to Pauli's principle, this in turn tends to lower the chance of screening configurations to occur, as the electrons will be further apart.
Bear in mind, all this doesn't mean that because of Hund's first rule, all the electrons will have their spins aligned (not possible), you should just interpret it as: the electrons will have their spins aligned when they can (energetically favorable). Now to decide which orbital states the electrons will occupy, Hund's second rule comes into play, which is another story!

Main reference used:  The Oxford Solid State Basics
A: To my mind, the above explanation (and others commonly presented) is missing an important piece though. In the semi-classical intuition presented, there should never be a preference for spins to align. The reason is that Pauli exclusion slapped on top of a classical picture simply restricts the phase-space of the system, thus reducing entropy. Sure, the regions it excludes are the high-energy unfavorable ones, but no-one was forcing the electrons to go into those regions in the first place. Any restriction of phase space should always be disfavored, and hence if the difference between aligned and anti-aligned spins was simply whether or not Pauli exclusion was in effect, then anti-aligned spins would always be favored. (This is actually the reason for the anti-ferromagnetic ground state in the half-filled tight-binding Hubbard model).
The situation in atoms (or for ferromagnets) is different because in a quantum description, we must account for the anti-symmetry of the wave-functions, not just Pauli exclusion. Thinking of Hartree-Fock approximation, we thus take:
$$\psi(r_1,r_2)=\psi_i(r_1)\psi_j(r_2) \pm \psi_i(r_2)\psi_j(r_1)$$
where $i$ and $j$ label the two electrons in question, and sign depends on whether spins are aligned or anti-aligned. This gives two contributions to the energy, direct (semi-classical):
$$\int dr_1 dr_2 \;\psi_i^*(r_1)\psi_i(r_1) \frac{e^2}{|r_i-r_j|}\psi_j^*(r_2)\psi_j(r_2)=\int dr_1 dr_2 \;p_i(r_1) \frac{e^2}{|r_i-r_j|}p_j(r_2)$$
and exchange (inherently quantum):
$$\pm \int dr_1 dr_2 \;\psi_i^*(r_1)\psi_j(r_1) \frac{e^2}{|r_i-r_j|}\psi_j^*(r_2)\psi_i(r_2)$$
Now the point is clear: this last term comes in with a plus sign if the spins are opposite, and with minus if they are the same. Hence, if it is positive, then aligned spins are favored. Whether it is or not is a quantitative question, and the arguments presented in previous answer are useful. Hence, here, and in ferromagnets, the spin-coupling is due to an inherently quantum phenomenon of exchange (hence it's called the exchange interaction in magnets).
