You can store the credentials in ~/.git-credentials as https://{user}:{password}@github.com and then add
[credential]
helper = store
to your ~/.gitconfig
EDIT:
I see you asked about gitlab and not github, my bad. I think the above solution should still work if you change github to gitlab, but I don’t know for sure