Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kaatinga/2f27968e38365ad63dea0c4650335713 to your computer and use it in GitHub Desktop.
Save kaatinga/2f27968e38365ad63dea0c4650335713 to your computer and use it in GitHub Desktop.
How to fix 'fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled'

Ops. https://gitlab.com': terminal prompts disabled

Ops. Username for 'https://codeberg.org':

Ops. etc

If you see this message, there is a short solution how to fix it here. In my case it appeared and it did not want to get fixed by many ways that are offered on the internet.

Some of the pieces of advice that did not work:

  1. Set git config --global --add credential.helper manager
  2. To add GIT_TERMINAL_PROMPT=1 to the enviroments.
  3. Use HTTPS authentification instead of SSH
  4. etc.

The actual reason is you do not have a key pair to work with your repository and/or you did not update git settings to use ssh.

step 1. Create a key pair. Fallowing the description on the page https://docs.gitlab.com/ee/ssh/, just add the public key to your SSH setting on gitlab.com, put your private key to .ssh folder (in my case it was id_rsa file) and check if it works by ssh -T [email protected] command (ssh -T [email protected], ssh -T [email protected]).

It will allow to access your repository using a private key.

step 2. Only for Golang: Point out that your repository or repositories are private. Use come to deparate patterns/repos. Set go env -w GOPRIVATE="gitlab.com/your_name*,github.com/your_name*,codeberg.org/your_name*".

step 3. Set git config --global url."[email protected]:".insteadOf "https://gitlab.com/". This will make Git use ssh to fetch and push changes (https must be disabled) even if you use https link to clone.

step 4. Optional: If you cloned a repo using https before to fix your settings in .gitconfig, like: git clone https://codeberg.org/your_name/your_repo.git you need to switch that repo to ssh. Go to the repo folder and run: git remote set-url origin [email protected]:your_name/your_repo.git

After the key is used, all the private packages are pulled and pushed without any trouble.

@charlos
Copy link

charlos commented Jan 10, 2024

ty ❤️

@MadisonLopez
Copy link

MadisonLopez commented Apr 11, 2024

It is working for me. Thank you so much.

@SagarNagalgawe
Copy link

Thank you !

@Hefan-scut
Copy link

It works! Thanks for saving my days!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment