Created
July 8, 2011 21:12
-
-
Save technoweenie/1072829 to your computer and use it in GitHub Desktop.
.netrc file so you can push/pull to https git repos without entering your creds all the time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
machine github.com | |
login technoweenie | |
password SECRET | |
machine api.github.com | |
login technoweenie | |
password SECRET |
Something interesting I found while testing the .netrc with go+git+GitHub: when using a GitHub personal access token (PAT) for the password
in the .netrc, the value given for login
can be any arbitrary value, it doesn't need to be the username that the PAT was generated for (it does need to be set to something though).
Instructions for GitLab folks, as this was one of my first results of Googling "GitLab .netrc":
machine gitlab.com
login oauth2
password <PERSONAL_ACCESS_TOKEN>
That enables:
- Cloning repos with https
- Accessing some private package registries with https (ex: pypi)
- Login in GitLab's private container registry using
docker login registry.gitlab.com
(of course your <PERSONAL_ACCESS_TOKEN> needs the correct capabilities)
Also, during CI:
build_job:
script:
- |
echo "
machine gitlab.com
login gitlab-ci-token
password $CI_JOB_TOKEN
" > ~/.netrc
- <stuff>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For those in the future wondering why this might not work - as of Go 1.13.x, Go uses proxies when downloading packages and verifying checksums.
In order to bypass the proxies, you'll need to set the environment variables
GOPROXY
,GONOPROXY
,GOSUMDB
,GONOSUMDB
to the appropriate values.For example, from the documentation:
This states:
*.corp.example.com
are private (and thus the proxy and checksum sites will not be used to download/verify them).proxy.example.com
as the proxy for downloading packages (though note that this does not set the checksum site).GOPRIVATE
variable.