Home > Blockchain >  git ls-remote failed when using personal access token
git ls-remote failed when using personal access token

Time:06-20

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>:[email protected]/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>:[email protected]/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>:[email protected]/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?

CodePudding user response:

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>:[email protected]/ command for testing.

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

git ls-remote https://oauth2:[email protected]/username/repo.git

  • Related