Skip to content

Instantly share code, notes, and snippets.

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

CarlosDomingues commented Feb 9, 2022

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