Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save actionjack/45425129e29da0cc9fdc46d5afc7c9b1 to your computer and use it in GitHub Desktop.
Save actionjack/45425129e29da0cc9fdc46d5afc7c9b1 to your computer and use it in GitHub Desktop.
Adding & Updating GitHub Access Token on Mac

As outlined here, there are a couple of situations where you need to authenticate with GitHub by using an Acces Token:-

  1. If you have Two-Factor Authentication (2FA) enabled.
  2. You are accessing an organisations protected content using SAML Single-Sign On (SSO).

Create an Access Token

In your GitHub account, go to Settings / Developer settings / Personal access tokens and select Generate New Token. Make a note of the token somewhere safe since this is the only chance you get to see it.

Add the token to your local OSX Key Chain

When you now need to authenticate with GitHub on the command line you will need to use the token instead of your password (even though git will ask for your Github password).

git clone https://github.com/username/repo.git
Username: your_username
Password: your_token

Using the token on your Mac the first time should automatically add it to your OSX Key Chain so that you do not need to enter it every time you are using the Github API. If you check your local git configuration you should see that there is a credential.helper key pointing to the OSX Key Chain.

git config -l

credential.helper=osxkeychain
user.email=joe.bloggs@gmail.com
user.name=Joe Bloggs

Updating the Access Token

If you need to regenerate the Access Token (maybe you got a new Mac and didn't make a note of your existing token) then follow the procedure before in your Github account settings to generate a new token.

Then, on your local Mac you can either use the Keychain Access app to delete the old token (search for Github.com in the App), or, use the following command.

git credential-osxkeychain erase

Now, the next time you do a clone/pull/push etc Github should prompt you for your new token on the command line and entering the new token should also add it to youe local Key Chain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment