1

I'm deploying my Vite's app through Vercel.

One of the dependencies is a private repository in the Github,
So I've created the personal token and provided it in the package.json

"dependencies": {
    ...
    "my-private-repo": "git+https://<personal_access_token>:x-oauth-basic@github.com/myusename/my-private-repo.git"
},

I've tried to build, Everything seems fine in the local
However, in Vercel build it's throwing me this:

error Command failed.
Exit code: 128
Command: git
Arguments: ls-remote --tags --heads https://<personal_access_token>:x-oauth-basic@github.com/myusename/my-private-repo.git

So I've found that git ls-remote is the actual problem

Here is when I run git ls-remote with token

git ls-remote https://<personal_access_token>:x-oauth-basic@github.com/myusename/my-private-repo.git
>>> remote: Invalid username or password

And here is when I run git ls-remote without token

git ls-remote https://github.com/myusename/my-private-repo.git
>>> 9a1daaf0faa44d30afd22121cb8da061d25d9044        refs/heads/main

How come git ls-remote only work when no credential is provided since this is a private repo? Isn't it weird for Github?

How I can solve this within Vercel config or Github config?

kitta
  • 1,723
  • 3
  • 23
  • 33
  • `:x-oauth-basic` is the wrong syntax here: the thing to the left of `@` in an https URL is `username:password`, not `password:authtype`. (GitHub will figure out the user name for you under the right conditions, including when using an oath2 token as in VonC's answer, so you can provide a fake user name there.) – torek Jun 19 '22 at 09:30

1 Answers1

1

How come git ls-remote only work when no credential is provided since this is a private repo?

Because of your local credential helper which has cached credentials in it.

git config --global credential-helper
xxx 
# replace xxx by the actual value

# check what is cached with:
printf "host=github.com\nprotocol=https" | git credential-xxx get

You can temporarily remove those with:

# replace 'You' with the account seen in the previous get command
printf "host=github.com\nprotocol=https\nusername=You" | git credential-xxx erase

Then try again locally the git ls-remote https://<personal_access_token>:x-oauth-basic@github.com/ command for testing.

As seen here, see also if the following syntax works better:

git ls-remote https://oauth2:TOKEN@github.com/username/repo.git

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250