Alternative read -> Creating a personal 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.
When you next interract with a private repository on the command line Github should challenge you for your credentials. When you are prompted to supply your Password for 'https://[email protected]': you enter your access token instead.
$ git clone https://github.com/username/repo.git
Cloning into 'repo'...
Username for 'https://github.com': your_github_username
Password for 'https://[email protected]': your_access_tokenUsing 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 interracting with 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
[email protected]
user.name=Joe BloggsIf you need to regenerate or revoke an existing Access Token then log into your Github account and navigate to Settings -> Developer settings -> Personal access tokens and choose to either Generate new token, or replace your existing token either by choosing Delete and Generate new token, or viewing your current token and choosing Regenerate token.
You can check if you have an existing token using the following command.
$ security find-internet-password -l github.comWhich should report something like this if it exists.
keychain: "/Users/jbloggs/Library/Keychains/login.keychain-db"
version: 512
class: "inet"
attributes:
0x00000007 <blob>="github.com"
0x00000008 <blob>=<NULL>
"acct"<blob>="joebloggs"
"atyp"<blob>="dflt"
"cdat"<timedate>=0x32303730303933373333343635395A00 "20200938235909Z\000"
...(truncated)Or else if it does not exist then you should see something like this.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.$ security delete-internet-password -l github.comIf you had a token previously stored then running the above should output something like the following.
keychain: "/Users/jblogs/Library/Keychains/login.keychain-db"
version: 512
class: "inet"
attributes:
0x00000007 <blob>="github.com"
0x00000008 <blob>=<NULL>
"acct"<blob>="joebloggs"
"atyp"<blob>="dflt"
"cdat"<timedate>=0x32303230303932383233343630395A00 "20200928234609Z\000"
"crtr"<uint32>="aapl"
... (truncated)
password has been deleted.Now, the next time you attempt a clone/pull/push etc on a private repo Github should prompt you for your Username/Password. Note that you enter your new token when prompted for Password.