Generate SSH Key if you don’t have one

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Copy the SSH Key to your clipboard

pbcopy < ~/.ssh/id_rsa.pub

Add the SSH Key to your GitHub account

  1. Go to your GitHub account
  2. Click on your profile picture
  3. Click on settings
  4. Click on SSH and GPG keys
  5. Click on New SSH Key
  6. Paste the SSH Key
  7. Click on Add SSH Key

Test the SSH Key

ssh -T git@github.com

HTTPS access

Create a Personal Access Token

  1. Go to your GitHub account
  2. Click on your profile picture
  3. Click on settings
  4. Click on Developer settings
  5. Click on Personal access tokens
  6. Click on Generate new token
  7. Add a note
  8. Select the scopes
  9. Click on Generate token
  10. Copy the token

Setup git to use the Personal Access Token

git config --global credential.helper store

Setup GOPRIVATE

go env -w GOPRIVATE=github.com/your_username/*

Go get the private repo

go get -u github.com/your_username/your_repo

Alternatice : Create a .netrc file in your home directory

machine github.com
login your_username
password your_token

Use the following command to create the file

echo -e "machine github.com\nlogin your_username\npassword your_token" > ~/.netrc

Test the setup

go get -u github.com/your_username/your_repo

If using .netrc use the following command to get the private repo

go get git@github.com:your-username/your-private-repo.git