.netrc - Access to privare repo without typing password

Posted on Aug 4, 2023

Create a GitLab/GitHub access token for your account.

Create a ~/.netrc file.

touch ~/.netrc

The contents of the ~/.netrc file.

cat ~/.netrc
# GitHub
machine <DOMAN_NAME>
login <YOUR_LOGIN>
password <YOUR_TOKEN>

# GitLab
machine <DOMAN_NAME>
login <YOUR_LOGIN>
password <YOUR_TOKEN>

# Corporate private repo
machine <DOMAN_NAME>
login <YOUR_LOGIN>
password <YOUR_TOKEN>

Do not forget to change the access rights to the file. This is due to storing data as plain text.

chmod 600 ~/.netrc

If you have a private repo, you can add an environment variable to go env.

go env -w GOPRIVATE=DOMAIN_NAME