DEV Community

abbazs
abbazs

Posted on • Edited on

19 2

How to access gitlab from git cli using personal access token?

Create a personal access token by following

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

Using the personal access token to authenticate, lets clone a repository.

Form your url as shown below. Replace the personal_token with the token you have got.

# To clone using personal token
git clone https://oauth2:personal_token@gitlab.com/username/project.git 
Enter fullscreen mode Exit fullscreen mode

If the project is already cloned and you have done few commits already by painstakingly providing the login and token every time then do this:

  1. Open the file .git/config in vscode or any editor you prefer
  2. Change the url as show below with your personal access token
[remote "origin"]
        url = https://oauth2:1AbCDeF_g2HIJKLMNOPqr@gitlab.com/yourusername/project.git
        fetch = +refs/heads/*:refs/remotes/origin/*
Enter fullscreen mode Exit fullscreen mode

For a more robust solution look at A function to clone git repository using gitlab personal access token

Billboard image

Monitoring as code

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (1)

Collapse
 
sespinozj profile image
sespinoza

Thank you! this helped me to set it up correctly, couldn't find good information about how to use it well.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay