Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
.netrc file so you can push/pull to https git repos without entering your creds all the time
login technoweenie
password SECRET
login technoweenie
password SECRET
Copy link

kleaver commented Jun 15, 2021

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).

Copy link

CarlosDomingues commented Feb 9, 2022

Instructions for GitLab folks, as this was one of my first results of Googling "GitLab .netrc":

login oauth2

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

(of course your <PERSONAL_ACCESS_TOKEN> needs the correct capabilities)

Also, during CI:

    - |
      echo "
      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