Herd mentality was first observed by the journalist Charles Mackay in his 1841 study of crowd psychology, Extraordinary Popular Decisions and the Madness of Crowds. Herd mentality happens when information that's available to the group is deemed more valuable than privately held knowledge, regardless of the source or quality of that information. We often follow the crowd when it comes to serious decisions out of the belief that "so many people can't be wrong."
Herd mentality originates from the general human need to be a part of a group. Confronting group opinions takes courage and conscious effort many people are not capable of – we know this notion under the name of conformism. But also, there is some safety in the herd. We feel it both when we make decisions and if the decisions turned to be wrong. When the latter happens, we believe that it was caused by something so extraordinary that nobody could predict. So, we shouldn't blame ourselves.
There is a very simple way not to fall victim to herd mentality. Making important decisions should be accompanied by pro and contra analysis, made on paper (not in our minds). If you believe that a decision is correct, try to collect as much evidence in favor of the opposite decision as possible. Ultimately you may stick to the first decision, but at least you will be definite that you did an excellent job of critical thinking.