In reference to Matthew 26, When Jesus was in the Garden of Gethsemane, Peter used a sword to cut off an ear. My question: Why did Peter have a sword? Why was he carrying a sword? Did Jesus know he was carrying a sword?
Thanks for the question.
Just look at Luke's account of that night.
35 And he said to them, “When I sent you without money bag, knapsack, and sandals, did you lack anything?” So they said, “Nothing.”
36 Then he said to them, “But now, he who has a money bag, let him take it, and likewise a knapsack; and he who has no sword, let him sell his garment and buy one.
37 For I say to you that this which is written must still be accomplished in me: “And he was numbered with the transgressors.’ For the things concerning me have an end.”
38 So they said, “Lord, look, here are two swords.” And he said to them, “It is enough.”
If you look at this parallel account of the night Jesus was betrayed, you will see Jesus warn them to be prepared and arm themselves. He contrasts with this the first time he sent them out when they lacked nothing, but this time, they needed to be ready.
In verse 36 he tells them to buy a sword if they didn't have one. In verse 38 they tell him that they have two swords and he says that would be enough.
Jesus needed them to be prepared for self-defense in the garden that night. When Peter used the sword he had for attacking the guards, and trying to protect Jesus, then Jesus rebukes him. Peter didn't understand that Jesus was meant to die and that it was his plan. These swords were only there for the self-defense of the disciples because Jesus did not want any of them to be hurt at all.
I hope this clears things up for you.
Please take the time to read all four of the gospels. Each one clears things up for the others, (especially John).