This is a simple G major arpeggio. Middle finger will play the 1st note (G), leaving the index to play B, and the 5th fret notes can play using pinky. Then reverse.
Once a string has another note higher than the previously played one, there's no need to leave the lower finger on. It makes no difference to the sound at all. You may, however, want to play the ...
If you're playing at the fifth fret then you can take your finger off the second fret, but you don't have to.
If you were playing a piece where the music goes back to the second fret immediately, then it might make more sense to leave that finger on while you finger the fifth fret.