Today I Learned — Fix for “Fatal: could not read Username for ‘https://gitlab.companyname.com’: terminal prompts disabled”

Introduction

go: gitlab.companyname.com/inbox/mediaproxy@v0.0.0–20190510132048–77ca670c6dcc: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /Users/pavelgordon/go/pkg/mod/cache/vcs/2d951819783281690e044152fbf2405ded1a3254778a249218ea484a3c1ac759: exit status 128:
fatal: could not read Username for ‘https://gitlab.companyname.com’: terminal prompts disabled

There are a couple of solutions to this problem that I found on internet after brief search, but none of them worked for me unfortunately, so I had to come out with my own.

Explanation

go get disables the “terminal prompt” by default.

env GIT_TERMINAL_PROMPT=1 go get github.com/mycompany/mypackage

or export it for the end of terminal session by running
export GIT_TERMINAL_PROMPT=1 and then running your go get or go mod download -x
This is a minor issue and is not a root cause.

go get can’t establish https connection to gitlab server

go env -w GOPRIVATE=gitlab.companyname.com

Force git client to use ssh over https. This will use our /.ssh, so make sure our ssh key exists and registered in our Gitlab. Here is how you can set up ssh keys for gitlab

git config — global url.”git@git.companyname.com:”.insteadOf “https://gitlab.companyname.com/"

That’s it! Enjoy your day.

Other solution

  • create a gitlab Personal Access Token with at least read_api and read_repository scopes.
  • create a ~/.netrc file with following content:
machine machine gitlab.com
login yourname@gitlab.com
password yourpersonalaccesstoken
  • use go get --insecure to get your module
  • do not use the .gitconfig insteadOf thingie

It didn’t work for me, but hey — it is worth a try.

Sources

--

--

Backend Engineer. Amsterdam.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store