A hammer-on is hitting a string with your fretting hand, but pressing it quickly so you can hear the note without strumming.
This is how I would suggest you learn how to do it.
1 – Start Easy
Make your guitar sound out by making several notes sound on their own without ever picking. Play a note, and then use your fretting hand to smack another note for a hammer on.
2 – Use Your Index Finger
3 – Put your ring finger two frets away to hammer on
4 – Adjust the power of your hammer on
5 – Practice the pentatonic scale with a hammer on
Now that you have learned to do hammer on, practice the pentatonic scale using the hammer-on technique and do it repeatedly so it comes naturally to you.
You can also introduce the hammer on anywhere across the neck to increase your playing speed, going from note to note with a new style.
Here is a video I made showing exactly how to do this great guitar technique.