Skip to content

Can I update the token of a cloned repo? #22434

Can I update the token of a cloned repo? #22434
Aug 16, 2021 · 8 answers

A long while back I cloned a repo I own with a PAT.

Recently, since the GitHub PAT algorithm update, I changed my PATs, so now the cloned repo can’t auth properly and therefor I can’t push to origin.

Is there a way to update the token of the cloned repo, so I don’t have to remove the local clone and clone it all over again ?

The solution to my original problem is the following:

$newGitHubPAT = "ghp_..."
$newOrigin = "https://token:$newGitHubPAT@github.com/owner/repo.git"
git remote remove origin # origin is the remote repo
git remote add origin $newOrigin

Basically you just remove the old origin that referenced the remote repository with the old token and add the origin with the new PAT.

Replies

8 suggested answers

Hi @aleks-ivanov, personal access tokens are associated with user accounts not your repository.
If you have not rẻ-entered your new PAT ata prinoy then most likely you are using a Git client where you Credential is cached.
You can safely delete your old cached Credential, if this is the case and you should get prompted to enter a new one in tbe next authenticated git command

For Windows example see here…

<a href="https://github.community/t/how-to-start-using-a-personal-access-token-to-authenticate-git-on-windows/163304/2">How to start using a personal access token to authenticate git on windows</a> <a class="badge-wrapper  bullet" href="/c/github-help/how-to-use-git-and-github/21"><span class="badge-category-parent-bg" style="background-color: #6a737d;"></span><span class="badge-category-bg" style="background-color: #ffd1ac;"></span><span style="" data-drop-close="true" class="badge-category clear-badge" title="Ask and answer questions regarding Git and GitHub.">How to use Git and GitHub</span></a>
If you are still using an existing cached password for you login you will need to remove it, the below will help, hopefully slight_smile Launch ‘Credential Manager’ on your Windows device. Switch to tab Windows Credentials (it default displayed tab Web Credentials on my device). A list of locally cached credentials are then shown Find an entry starting something like git:htttps//login@github.com (this will be an exist cached entry for your username/password. You can safely delete this by …
0 replies

I never use cached credentials, I always use per cloned repo authentication like this:

git clone https://token:jnibf29833fibf293gfb2987fg42gb0vf@github.com/aleks-ivanov/project.git
0 replies

That doesn’t look like one of the current PATs (which should start with ghp_). However, if that is an old token, you should revoke it now after sharing it on a public forum. ⚠️

0 replies

Not an actual token of course, just a random smash of the keyboard as example

0 replies

If your token is entered correctly but still not working you coul check it has the correct repo scope enabled.
I don’t personally specify in git like you are doing here but have you tried format
username:token@…

0 replies

The solution to my original problem is the following:

$newGitHubPAT = "ghp_..."
$newOrigin = "https://token:$newGitHubPAT@github.com/owner/repo.git"
git remote remove origin # origin is the remote repo
git remote add origin $newOrigin

Basically you just remove the old origin that referenced the remote repository with the old token and add the origin with the new PAT.

0 replies
Answer selected

This works, but is potentially dangerous because the token ends up stored on your disk unencrypted. Anyone with access to the filesystem could copy it.

0 replies

I agree, but it is really convenient 🙂

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants