Skip to content

Git Tips and Tricks

Cory Martin edited this page May 26, 2023 · 2 revisions

GitHub Personal Access Tokens

On August 13, 2021, GitHub started requiring the use of personal access tokens to connect to GitHub over https/ssh.

Create a Token

  • Go to github.com
  • At the top right, click your profile picture, then click Settings from the drop down menu.
  • On the left menu, click Developer settings
  • On the left menu, click Personal access tokens
  • Click Generate new token
  • Give it a name under Note, make sure all under repo are checked (and check whatever else you want to allow this token to have permissions for
  • Now once you have a token generated, it will be your password when you git clone or git pull or git push.
  • Copy/save this token somewhere! Once you leave this page you cannot view it again, you'll have to generate a new one.

Cache Your Token

Being prompted to enter your token/password 100x a day is annoying and inefficient. You can create a file that will be used to store this token for future use.

Create a .netrc file

In your home directory, create a .netrc file (edit it if it exists already)

vi ~/.netrc

Inside this file have the following lines

machine github.com
login MY_GITHUB_USERNAME
password MY_PERSONAL_ACCESS_TOKEN

Replace the above with your login name and paste in the token generated from the above steps

Save this file. Then ensure that the permissions are for just you to read/write

chmod 600 ~/.netrc

Now, Git should never prompt you for your password again! At least until the token expires.