Why did they bar marriage between a boy and a girl belonging to the same Gotra?  and why only son carries the gotra of father why not daughter ?

The Gotra is a system which associates a person with his most ancient or root ancestor in an unbroken male lineage. So Gotra refers to the root person (मूल पुरुष) in a person's male lineage.

The word Gotra is formed from the two Sanskrit words Gau (Cow) and Trahi (meaning Shed).
So Gotra means Cowshed, where in the context is that Gotra is like the Cowshed protecting a particular male lineage.

A Bride and a Bridegroom belonging to the same Gotra are considered to be siblings. The reason given was since they belonged to the same ancestor,.it will be like a brother marrying a sister which is known to cause genetic disorders in their offspring

Humans have 23 pairs of Chromosomes and in each pair one Chromosome comes from the father and the other comes from the mother. So in all we have 46 Chromosomes in every cell,of which 23 come from the mother and 23 from the father.

Of these 23 pairs, there is one pair called the “Sex Chromosomes” which decide the gender of the person. During conception, if the resultant cell has XX sex chromosomes then the child will be a girl and if it is XY then the child will be a boy. 
X chromosome decides the female attributes of a person and Y Chromosome decides the male attributes of a person. 

Since only men have Y Chromosomes, son always gets his Y Chromosome from his father and the X Chromosome from his mother.On the other hand daughters always get their X Chromosomes, one each from both father and mother.

So the Y Chromosome is always preserved throughout a male lineage, while the X Chromosome is not preserved in the female lineage because it comes from both father and mother.

Women never get this Y Chromosome in their body. And hence Y Chromosome plays a crucial role in modern genetics in identifying the Genealogy ie male ancestry of a person. Hence the Gotra of a woman is said to be that of her husband after marriage.

The Vedic Rishis had observed the degeneration of the Y Chromosome and they wanted to maintain as many individual healthy unique Y Chromosome lineages as possible. That would give a fair chance for males to continue to exist because Y Chromosomes get passed on over generations with almost negligible change in their genetic combinations, as they do not take part in mix and match with other Chromosome.

So if the Rishis could devise a mechanism where in a given Y Chromosome had very little chance of adding more genetic defects in it, then they could probably succeed in either slowing down further degeneration of the Y Chromosome or even probably completely stop any further degeneration of the Y Chromosome. And the only way to stop that was to ensure that the 5% of the Y chromosome which can be mixed and crossed over with its X counterpart be protected so that the remaining 95% which does not take part in the mix and match process stays healthy.

Now we know even in modern Genetics that marriages between cousins will increase the risk of causing genetic disorders.

That is because, say suppose there is a recessive dangerous gene in one person. What this means is that say a person is carrying a dangerous abnormality causing gene in one of his chromosome, but whose effect has been hidden in that person (or is not being expressed) because the corresponding gene in the pairing Chromosome is stronger and hence is preventing this abnormality causing gene from activating.

So if the Vedic Rishis had allowed marriages within the same Gotras, then there were chances that the resulting male can be a victim of
such defective gene expression, and any such gene expressions which took place in the 5% exposed area of the Y Chromosome would be fatal for the continuity of that Y Chromosome. Even after hundreds of generations there would still be chances of any defective genes being propagated within these successive generations, and marriage within the same Gotra would provide a golden opportunity for these genes to express themselves, there by causing the genetic abnormality in the offspring.

And hence the ancient Vedic Rishis created The Gotra system where they barred marriage between a boy and a girl belonging to the same Gotra no matter how deep the lineage tree was,in a bid to prevent inbreeding and completely eliminate all recessive defective genes from the human DNA.

This is called the amazing Bio-Science by our Maharishis. Our Rishis had the "GENE MAPPING" sorted out thousands of years ago. 🙏🚩