31

I have started working on Golang project. While building with make, I am getting following error:

fatal: could not read Username for 'https://github.com': terminal prompts disabled

To handle this, I have done following after going through similar post go get results in 'terminal prompts disabled' error for github private repo :

export GIT_TERMINAL_PROMPT=1

But this did not solve the problem, now it seems to be asking username and password in infinite loop.

My git config is as follows:

$git config --list

remote.origin.url=git@github.com:GolangProjects/Project1.git

Even after this config, why it keeps on using https instead of SSH, not getting any clue. Please help.

torek
  • 448,244
  • 59
  • 642
  • 775
Joy
  • 4,197
  • 14
  • 61
  • 131
  • Does your Makefile contain any invocations of `git` or any program that might use it, like a package manager? Do you have any submodules in your project? – bk2204 Jan 18 '20 at 03:29
  • Yes as part of build, it pulls and installs go dependencies. – Joy Jan 18 '20 at 03:34
  • Consider providing a [mcve]. What commands do you run from your Makefile? – torek Jan 18 '20 at 09:56

3 Answers3

47

Create an SSH key instead and use it as a default login method for you git repo. You can follow this link to create an ssh key for authentication on your machine:

Generating a new SSH key and adding it to the ssh-agent

And then use this to default your login method to use ssh keys instead of your credentials:

git config --global url.ssh://git@github.com/.insteadOf https://github.com/
Himanshu
  • 639
  • 8
  • 12
  • 6
    A word of warning to Mac/iOS developers - the above global git config will fix things on the command line but will break Git in Xcode. – Luke Redpath Apr 28 '21 at 12:11
  • do you have a solution that wont? I am currently suffering this issue with fastlane. – Xaxxus Feb 15 '22 at 18:33
1

Is one of your imports from a private repo?

If so, you need to let Go know about it.

go env -w GOPRIVATE=github.com/mycompany/*

or

export GOPRIVATE=*.corp.example.com,github.com/mycompany/*

(I had the same problem, and took this from https://stackoverflow.com/a/60323360/20837494

0

Had the same issue with git fetch:

Fetching the repository
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +refs/heads/master*:refs/remotes/origin/master* +refs/tags/master*:refs/tags/master*
  Error: fatal: could not read Username for 'https://github.com': terminal prompts disabled
  The process '/usr/bin/git' failed with exit code 128
  Waiting 14 seconds before trying again

To fix that you have to update the repo secrets token.

Andry
  • 2,273
  • 29
  • 28
  • Thank you for the hint. I had the same issue on GitHub Actions, and the issue was resolved after I updated the variable for the Personal Access Token (PAT). – Goran Vasic Jul 31 '23 at 07:28