When making decisions judges must follow the law as set out by a higher court that has previously tried a similar case. There are two exceptions.
The first is overruling. This doctrine allows the court to declare a previous ruling wrong or outdated. This can be due to a change in statute, a change in society or because the previous court was simply mistaken to the law. The key limitation to this doctrine is that a court can only overrule a 'lower' court - for example the High Court must always follow precedent of the Court of Appeal while the CoA can overrule the HC. The only court that can overrule itself is the Supreme Court (previously the House of Lords) with the limited exception that the CoA can overrule itself if it has previously made two conflicting judgements, in which case it must pick one. A topical and clear example of overruling is the Supreme Court overruling the High Court in R(Miller) No.2 regarding the powers of the government to prorogue parliament.
The second way to avoid the doctrine of precedent is by distinguishing the cases. This is where the court declares that the material facts of the case are different to the previous case and as such the precedent is not relevant. Distinguishing has been used in cases where the facts appear to be the same but the court wishes to diverge from precedent and as such is a strong power of the courts.