How to add a GitHub personal access token via the command line on a Mac

It’s been a little while since I’ve had to add a new GitHub personal access token via the command line to be able to clone a GitHub repo. When I first started using GitHub I always used to go the easy route and just use a password. Developers and security people especially love to make things complicated though, so you can’t use a password anymore. This is actually an old change, not something new, but I found today that the easiest way to add a new PAT has actually change. According to Claude, you can use the GitHub CLI, “gh”, to add new PATs. This seems a little different than what I used to do before, so I wanted to write up a quick post on how to do this in case anyone else happens to be looking for the same information.

  1. Create your new Personal Access Token at github.com. After logging in, click on your profile icon > settings > developer settings > Personal access tokens > Tokens (classic) > Generate new token > Generate new token (classic)
  2. After Creating your new token, make sure to save it somewhere you aren’t going to lose it.
  3. Assuming you have brew installed on your Mac, run $ brew install gh
  4. In a new terminal window, login: $ gh auth login
  5. Select paste an authentication token, then paste in your PAT
  6. Last, in a new terminal window, clone your desired repo (assuming it’s your own repo which you have access): $ git clone https://github.com/orgNameHere/repoNameHere
 

topherPedersen