Easyread
Published in

Easyread

Today I Learned — Fix: go get private repository return error terminal prompts disabled

Fixing fatal: could not read Username for ‘https://githost[.]something': terminal prompts disabled

I’ve some project stored separated into 3 git-host providers: Github, Gitlab, and Bitbucket. Because I was a low-profile software engineer, I use both in Gitlab and Bitbucket for the private repository and Github for public repository XD.

I like Github very much, but my current financial status forced me to reduce any not so important cost just for my personal hobby and private projects XD.

So, a few days ago, I’m trying to create a project of Golang and stored it in Gitlab. And this project has 2 dependencies to my other library. One of them stored in Bitbucket, and another one in Gitlab.

To simplify, I will tell it in an example. Let’s say I have 3 projects.

  • math library project in bitbucket (private repository)
  • multiply library project in Gitlab (private repository)
  • samplecool project in Gitlab(private repository)

So, the samplecool project use the math and the multiply as its dependencies, means, the math and multiply is imported in samplecool project.

package samplecoolimport(
"bitbucket.org/bxcodec/math"
"gitlab.com/bxcodec/multiply"
)

And when I trying to go get the samplecool‘s dependencies, this error happens:

$ go get -v
# cd .; git ls-remote https://bitbucket.org/bxcodec/math
fatal: could not read Username for 'https://bitbucket.org': terminal prompts disabled
go: missing Mercurial command. See https://golang.org/s/gogetcmd
package bitbucket.org/bxcodec/math: https://api.bitbucket.org/2.0/repositories/bxcodec/math?fields=scm: 403 Forbidden
Fetching https://gitlab.com/bxcodec/multiply?go-get=1
Parsing meta tags from https://gitlab.com/bxcodec/multiply?go-get=1 (status code 200)
get "gitlab.com/bxcodec/multiply": found meta tag get.metaImport{Prefix:"gitlab.com/bxcodec/multiply", VCS:"git", RepoRoot:"https://gitlab.com/bxcodec/multiply.git"} at https://gitlab.com/bxcodec/multiply?go-get=1
gitlab.com/bxcodec/multiply (download)
# cd .; git clone https://gitlab.com/bxcodec/multiply.git /Users/imantumorang/go/src/gitlab.com/bxcodec/multiply
Cloning into '/Users/imantumorang/go/src/gitlab.com/bxcodec/multiply'...
fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled
package gitlab.com/bxcodec/multiply: exit status 128

If we look for more detail, the errors I found is:

fatal: could not read Username for 'githost.something': terminal prompts disabled

I see a similar error happened here. After finding the solution on the internet, I found a few commands that help me to solve this.

Fixing fatal: could not read Username for Gitlab: terminal prompts disabled

For Gitlab case, This command should fix this error (copy this to the terminal)

$ git config --global url."git@gitlab.com:".insteadOf "https://gitlab.com/"

This will use our /.ssh, so make sure our ssh key exists and registered in our Gitlab.

To ensure this command works, when we see in .gitconfig there will be an addition to the .gitconfig something like this:

$ cat ~/.gitconfig
[url "git@gitlab.com:"]
insteadOf = https://gitlab.com/

Fixing fatal: could not read Username for Bitbucket: terminal prompts disabled

The same goes for bitbucket.

$ git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/"

And my .gitconfig will change into like this below:

$ cat ~/.gitconfig
[url "git@gitlab.com:"]
insteadOf = https://gitlab.com/
[url "git@bitbucket.org:"]
insteadOf = https://bitbucket.org/

After doing this in both Gitlab and Bitbucket, now I can go get all the dependencies.

And this also works for Github too. If you try to GitHub, just change the URL target and URL origin.

$ git config --global url."git@github.com:".insteadOf "https://github.com/"

--

--

--

Easy read, easy understanding. A good writing is a writing that can be understood in easy ways

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
Iman Tumorang

Iman Tumorang

Software Engineer - Writer - Open Source Enthusiast - Startup Enthusiast. Reach me out in https://imantumorang.com for fast response :)

More from Medium

How to Check nil Interface in Golang?

Building a Book Store API in Golang With Gin

Redis to REST, securely

Concurrency in Golang