For clarity, I'm just going to give the directions in terms of what you should add to .pinerc. You can also set all of these setting using the configuration interface if you wish.
To get your mail via IMAP:
inbox-path={imap.gmail.com/ssl/user=username@gmail.com}
Include this to make sure you have access to all of the various gmail folders:
folder-collections=Gmail {imap.gmail.com/ssl/user=username@gmail.com}[]
I find this useful to mimic "archiving":
default-saved-msg-folder=[Gmail]/All Mail
To send mail via gmail, you need this in .pinerc:
smtp-server=smtp.gmail.com:587/tls/user=username@gmail.com
Also, I find that these two settings improve performance a lot:
rsh-open-timeout=0
disable-these-authenticators=GSSAPI
If you want alpine to remember your password for you, you can run this command in your home directory:
touch .pine-passfile
The first time you use alpine after running this command, you will be asked whether you want to save your password for later use each time you enter one.
Best Answer
Do as recommended by Andreatsh in the comments.
Go to http://myaccount.google.com
Then "Sign-in & security" -> "Signin in to Google" -> "App password"
Once you create the one time password you will also have to run:
This makes it so when you enter the gmail folder on Alpine you will be asked if you want to save the password.