Using GitLab token to clone without authentication

Question

I want to clone GitLab repository without prompt for my automation script, by using my private token from my GitLab account.

Can someone provide me a sample?

I know I can do so with user and password:

git clone https://" + user + ":" + password + "@" + gitlaburl;

and I know it is possible with ssh key

But, both options are insufficient.

Answer

This is how you do it:

git clone https://oauth2:[email protected]/vendor/package.git

Updates were rejected because the tip of your current branch is behind its remote counterpart

Where does the .gitignore file belong?