Interesting question you have posed. There have been a few errors in answers here, although their sentiments are essentially correct.
Although Jesus never gave up His divinity, He did not have the same attributes as God the Father. He was not omniscient, nor omnipresent (that's why he told the disciples it was better for them if He left so that Holy Spirit would come), nor omnipotent; He received information and power from Holy Spirit (just like we do). Jesus' power to do miracles was not from His ability but from Holy Spirit. (In fact, in John 14:12 Jesus says, “Most assuredly, I say to you, he who believes in Me, the works that I do he will do also; and greater works than these he will do, because I go to My Father.") Those who believe in Him can only do those 'works' through the power of Holy Spirit.
Since Jesus was not conceived from the seed of man, He was not born with innate sin inherited from Adam. Yet He was born of a woman so He lived life as a human. Therefore, He faced all the usual situations that we face. Remember the two greatest commandments: ‘You shall love the Lord your God with all your heart, with all your soul, with all your strength, and with all your mind,’ and ‘your neighbor as yourself.’ (Deut. 6:5, Matt 22:37, Mark 12:30, Luke 10:27) That is where we are all tempted. Either we want to make something or someone else more important than God, or we do not care enough about our neighbor. All sin can be traced back to those two things. Jesus had plenty of opportunities in His life to care more about Himself than His neighbor, yet did not. We know when Satan tempted Him to lift Satan or Himself higher than God, He did not.
However, His ability to become the sacrifice for us came from His position as Son of God and son of man. Since He never sinned, He did not have to pay for His own sins; and since He was the Son of God, His position gave Him the credentials. He atoned for our sins because God the Father credited to Him our sinfulness and credited to us His righteousness. (See Romans chapters 4 and 5.)
Does this explanation help you?