Floris Devreese
Floris Devreese

Reputation: 3667

clone GitHub repo with fine-grained token

With classical Github tokens you can clone a repo like this:

git clone https://<your-token>@github.com/owner/repo.git

This doesn't work with the new fine-grained tokens.

How do you clone a GitHub repo with the new fine-grained tokens?

Upvotes: 28

Views: 18544

Answers (5)

erPe
erPe

Reputation: 578

I needed the same setup when working with Atlantis. Idea was to use the token when cloning private modules ( from private repositories.

I did provide the set of permissions as mentioned by https://stackoverflow.com/a/78280453/4540216

But then to streamline the operations I configured the token globally

> git config --global url."https://github_pat_1******[email protected]".insteadOf "https://github.com/"

Lastly to clone I used it with the following ( mind the double slash )

git clone https://github.com//SomeOrg/SomeRepo.git

Hope this helps!

Upvotes: 0

Thore
Thore

Reputation: 440

In my case the fine-grained access token didn't work because the repo I was trying to clone is from an organisation that requires SAML SSO (docs).

Apparently SSO is not (yet) supported by the fine-grained access tokens (as of August 2024). When using a classic Personal Access Token and configuring it for SSO, cloning the repo worked.

Upvotes: 1

It's the same for fine-grained tokens too.

git clone https://<your-token>@github.com/owner/repo.git

You need to grant Permissions Commit statuses, Contents, Pull requests and Metadata as Read to be able to Clone repositories. And the same Permissions need to the Read and Write to be able to push changes.

I wish the Github Permission names were a bit more intuitive or better organized :D It seems like most people get annoyed with which permission to give and fall back to the classic token.

Upvotes: 13

Elina Eliel
Elina Eliel

Reputation: 41

git clone https://${token}@github.com/${owner}/${repo}.git

Upvotes: 1

Floris Devreese
Floris Devreese

Reputation: 3667

When using fine-grained tokens you have to prefix the token with oauth2: user.
like this:

git clone https://oauth2:<your-fine-grained-token>@github.com/owner/repo.git

*credits to Andy's comment here

Upvotes: 44

Related Questions