Peter was very vocal about never denying the Lord, and his actions proved that he meant what he said. There were only two swords among the disciples. Peter was willing to take on these six hundred soldiers. This spelled certain death or imprisonment.
Peter wanted to stand with the Lord, but he was not prepared spiritually. He was still strong in his own ability. If the battle would have been in the physical realm, Peter would have fought to the death as he proved. But when Jesus told Peter to put up his sword and not resist with his physical power, Peter was confused.
Peter only knew how to rely on the flesh. When Jesus refused to allow Peter to fight with his sword, he was defenseless. If he would have been praying with Jesus, as instructed, Peter would have been built up spiritually and able to stand with Jesus spiritually without denying Him. As the prophet Zechariah said, "Not by might, nor by power, but by my spirit, saith the LORD of hosts" (Zechariah 4:6).
We may sincerely desire to never deny our Lord, but it takes more than desire; it takes preparation. We all have been taught how to rely on ourselves, but we have to learn how to be strong in the Lord and in the power of His might (Ephesians 6:10). Just as in the physical realm, where muscles have to be exercised to become strong, we have to exercise ourselves unto godliness (1 Timothy 4:7).