In Matthew 18, Jesus said: "If your brother sins against you, go and show him his fault, just between the two of you. If he listens to you, you have won your brother over. But if he will not listen, take one or two others along, so that 'every matter may be established by the testimony of two or three witnesses'. If he refuses to listen to them, tell it to the church; and if he refuses to listen even to the church, treat him as you would a pagan or tax collector." (Mt 18:15-17).
Let's compare this to Paul's actions in Galatians 2. "When Peter came to Antioch, I opposed him to his face, because he was clearly in the wrong... When I saw that they were not acting in line with the truth of the gospel, I said to Peter in front of them all..." (Ga 2:11,14).
Was Paul's behaviour here justified? He was certainly right in that Peter was not living up to the truth of the gospel, but was his response correct? I don't think it was. Yes, Peter was seriously wrong. Yes, he needed to publicly acknowledge this, because it could have (and did) lead others astray. But Paul should have confronted him privately first, allowing Peter the opportunity to recognise his mistake, and confess it publicly.
There are two points from this: firstly, as brilliant as Paul was, even after his conversion he still was far from perfect. He still failed to live up to the standards required by Jesus. We see this in many places in Acts and in his own writings. Secondly, we are to follow the example of Jesus, not the apostles, and not anyone else.


Comments
The difference between the situations is that Jesus talked about one brother sinning against another. Peter did not sin against Paul, instead Peter was warping the doctrine of the church to suit tradition. The verses refer to different situations.