Nicolas Miari
Nicolas Miari

Reputation: 16256

Personal Access Token in Github not working

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...

Upvotes: 12

Views: 35415

Answers (5)

user1007074
user1007074

Reputation: 2596

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.

Upvotes: 0

Taha Syed Muhammad
Taha Syed Muhammad

Reputation: 31

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.

Upvotes: 1

LaurentBaj
LaurentBaj

Reputation: 548

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

Upvotes: 5

FullStackEngineer
FullStackEngineer

Reputation: 311

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/

Upvotes: 9

VonC
VonC

Reputation: 1326766

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.

Upvotes: 3

Related Questions