Personal Access Token in Github not working
Asked Answered
I

5

11

I have a private repository on my personal Github account that I work on from time to time, but not on a daily basis.

The repository has been cloned using HTTPS (not SSH or git://). In order to access the repository from the command line, I set up a personal access token as explained here: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/

I am positive it did work back then (I moved away from SSH precisely because this kind of persistent headache).

However, when I try to push to my repository after a few weeks I get the dreaded:

$ remote: Repository not found. fatal: repository
$ 'https://github.com/nicolas-miari/MyPrivateRepo.git/' not found

What am I missing?


Addendum: I deleted the token on Github, created a new one, and followed the instructions here: https://help.github.com/articles/updating-credentials-from-the-osx-keychain/ to clear the old token stored in the keychain. I was able to re-clone my private repository. However,

  1. This still doesn't explain why the previous access token suddenly stopped working, and

  2. My keychain had two "Internet password" entries matching the host github.com: The access token I just deleted, and the my web login password for a different Github account (work). Maybe this has something to do with it?

Background info: To avoid having to log in/out frequently, I have my work account's web credentials saved in Safari (and the Keychain), and my personal account's web credentials saved in Firefox.


Addendum 2: After running the command given on the linked help page:

$ git credential-osxkeychain erase
  host=github.com
  protocol=https
  [enter]

...the additional password is gone from the Keychain (only my newly added Personal Token remains), however I can still log in to my account on Safari...?


Update: Now I can't push to repos from my work account (which credentials I deleted from Keychain...). This system really needs a healthy dose of Just Works...

Illicit answered 7/6, 2017 at 5:11 Comment(1)
Can you push manually, by entering as a password a PAT (Personnal Access Token) registered to your work account?Perch
P
3

Don't forget that Safari has access to iCloud Keychain

That could explain why, even though you have cleared your local OSX keychain, you still can log on to GitHub with Safari.

Perch answered 7/6, 2017 at 6:25 Comment(2)
Indeed. Do you think the local (non-iCloud) keychain Password entry was getting in the way of the Access Token? I'll have to wait a couple of weeks and see if my current setup breaks again...Illicit
@NicolasMiari Yes, it is possible but I don't see a bug report on that yet.Perch
S
9

I have a private repository that I have a dependency on, using https://github.com... in my package.json. I have ssh set up on my computer, also I have personal access token. Even though I provide my personal access token as the password it fails. So I changed my git config url using the following and it worked like a charm.

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

You can double check your ~/.gitconfig to see something like this:

[url "[email protected]:"]
    insteadOf = https://github.com/
Sharmainesharman answered 4/6, 2019 at 20:43 Comment(2)
thanks man, this helped me fix the issue :)License
This is actually almost fiendishly brilliant. Thanks!Aram
C
5

I tried all the suggestions I could find and the only thing that worked for me was deleting Git on my computer. Once I downloading it again it asked me to to login with browser, which I did and then it worked

Carnahan answered 20/4, 2021 at 14:19 Comment(1)
this was also only thing that worked for meGringo
P
3

Don't forget that Safari has access to iCloud Keychain

That could explain why, even though you have cleared your local OSX keychain, you still can log on to GitHub with Safari.

Perch answered 7/6, 2017 at 6:25 Comment(2)
Indeed. Do you think the local (non-iCloud) keychain Password entry was getting in the way of the Access Token? I'll have to wait a couple of weeks and see if my current setup breaks again...Illicit
@NicolasMiari Yes, it is possible but I don't see a bug report on that yet.Perch
F
1

My colleague was facing the same issue on Linux, and we just logged out from the browser and logged back in, and git commands from the terminal started working with PAT, don't know the relation of terminal command with browser authentication but it worked.

Federico answered 17/8, 2021 at 6:31 Comment(1)
Had the same issue. After creating a new fine-grained PAT had to log out via browser and log back in before new PAT started working.Moniquemonism
A
0

Best guess is that the token expired.

At the time of writing, you can set the token expiration period. If you attempt to select "No expiration", the GitHub UI gives the explicit warning:

GitHub strongly recommends that you set an expiration date for your token to help keep your information secure.

When you inspect existing Personal Access Tokens, you can see an indication of when it was last used and when it's due to expire.

Not sure about when this question was asked 5 years ago but, I assume, as this type of auth was optional back in the day the UI was probably less helpful. The OP mentioned using the repo occasionally and if you set up a token for the first time with expiry of 30 or 60 days, it's easy to have forgotten that a couple of months later.

Appalling answered 5/7, 2022 at 21:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.