noobie-php
noobie-php

Reputation: 7233

GitHub - fatal: could not read Username for 'https://github.com': No such file or directory

I have the following problem when I try to pull code using git Bash on Windows:

fatal: could not read Username for 'https://github.com': No such file or directory

I already tried to implement the accepted solution provided here:

However the problem still persists.

After adding/removing origin I still get the same error.

Could advise on this issue?

Thanks!

Upvotes: 265

Views: 681722

Answers (30)

Malik Hamza
Malik Hamza

Reputation: 350

If you are trying to clone private repo in colab

Try this command:

!git clone https://username:[email protected]/username/repo_name.git

Example command:

    !git clone https://"user":"abcdefghikl"@github.com/username/repo_name.git

Upvotes: 1

marin3r0
marin3r0

Reputation: 1

I don't know how many people came here for this reason: You tried to install a plugin for NVim with lazy and you kept getting this error.

Do this:

Check if you typed in the name of the repository right.

I was looking for answer for a good while and all I had to do was check the name of the repository.

Upvotes: 0

Mukesh Lekhak
Mukesh Lekhak

Reputation: 1

I understand how frustrating it can be to face a similar issue, as I did recently.

fatal: could not read Username for 'https://github.com': No such file or directory

To solve this, I did the following.

  1. Copy the repo URL
  2. Change the repo URL in this format (https://username:[email protected]/username/remainingUrl where username and password is added.
  3. Now you can simply use git clone https://username:[email protected]/username/remainingUrl

*Note: Password is not the password you use to log in on the web; it is a token generated from Setting >> Developer Setting >> Personal Access Token *

I'm optimistic that this solution will be beneficial to someone facing a similar issue. Best of luck!

Upvotes: -1

LRaja
LRaja

Reputation: 3

I had similar issues updating the repo from jenkins, while it was working good in cmd line without any errors. After changing the repo to public, it worked for me from jenkins as well. Check if the user has enough rights to perform the operation.

Upvotes: 0

Batel
Batel

Reputation: 45

If you're encountering this error while running go mod download within a Dockerfile, I experienced a similar issue. What resolved it for me was implementing the following changes in my Dockerfile:

RUN go env -w GOPRIVATE="github.company.com"
RUN git config --global url."ssh://[email protected]".insteadOf "https://github.company.com"
RUN mkdir -p /root/.ssh && ssh-keyscan github.company.com >> /root/.ssh/known_hosts
RUN --mount=type=secret,id=sshKey,dst=/root/.ssh/id_rsa go mod download

This sets the private repository to use SSH instead of HTTPS and ensures that go mod download uses the correct SSH key.

Upvotes: 1

ChrisZZ
ChrisZZ

Reputation: 2181

I meet same problem when pushing a new commit to a private gitlab.

I do git push in a powershell, and seems like I ran "git push" with a "ctrl+c" to stop it.

My solution:

  • start a new git-bash terminal
  • change to the same local repo directory
  • then do git pull and git push

Upvotes: -1

XiaoBanni
XiaoBanni

Reputation: 101

Issue: Git Pull/Push gets stuck when using SSH authentication.

Analysis:

Running ssh -vT [email protected] reveals a hang:

(base) ➜  .ssh ssh -vT [email protected]
OpenSSH_7.6p1 Ubuntu-4ubuntu0.5, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.255.112] port 81.

Running ssh -vT -p 22 [email protected] shows that the connection can be made.

Checking /etc/ssh/ssh_config reveals that the connection port is set to 81.

image-20230803191919046

Solution:

Edit ~/.ssh/config, and write:

Host github.com
    Port 22

Upvotes: 0

Komolafe Ezekiel dare
Komolafe Ezekiel dare

Reputation: 115

This solved my problem i ran

git config --global --unset credential.helper

Try using an SSH connection instead of HTTPS. Set up SSH authentication for your GitHub account and update the repository URL in your deployment script to use the SSH format ([email protected]:/.git). This eliminates the need for username and password authentication.

Upvotes: 0

Raj Kanchan
Raj Kanchan

Reputation: 618

I also had the same issue of connecting to my account to a private GitLab repository. I found the solution in this very Stack Overflow page but still having doubts. Posting this image illustrating what needs to be done.

Credential Helper to Resolve Git Account Issue

Upvotes: 2

Fayaz
Fayaz

Reputation: 1191

I faced the exact same problem. This problem occurred when I cloned a repo using HTTPS URL and then tried to push the changes (using Shell on Linux/Mac or Git Bash on Windows):

git clone https://github.com/{username}/{repo}.git

However, when I used SSH URL to clone, this problem didn't occur:

git clone [email protected]:{username}/{repo}.git

In case you already cloned the repo using HTTPS and don't want to redo everything, you may use set-url to change the origin URL to SSH URL:

git remote set-url origin [email protected]:{username}/{repo}.git

Note: I have SSH key added to my GitHub account. Without setting up SSH key, this method will not work either.

BTW, git clone or pull should work without any of these changes. These are needed only when you git push after clone.

Upvotes: 59

Adnan Khan
Adnan Khan

Reputation: 509

If your repo is private then

Instead of this format

https://github.com/username/<project_name>.git

Use this format

[email protected]/<project_name>.git

You can get a correct url under SSH option

Go To Your Github Repo -> Click on Code -> Select SSH -> Copy your repo URL

Hope this helps.

Upvotes: -2

Nikhil
Nikhil

Reputation: 47

Here is the simple trick that can work

android studio -> settings -> version control -> git -> use credential helper

have fun

Upvotes: 3

Radhika bajaj
Radhika bajaj

Reputation: 155

  1. From the Android Studio terminal execute git pull

    example: test@test:~/StudioProjects/dummy-project-android$ git pull

  2. Add the user name

    example: test@test:~/StudioProjects/dummy-project-android$ "username"

  3. Add the user password

    Password for 'https://[email protected]':"password"

After that, we can perform the rest of the operation

Upvotes: -1

Fawaz
Fawaz

Reputation: 3560

In my case I had to setup "personal access token" under GitHub:

  1. settings -> developer settings

  2. and enable SSO.

Upvotes: 1

Creative Magic
Creative Magic

Reputation: 3151

Short Answer:

git init
git add README.md
git commit -m "first commit"


git remote add origin https://github.com/{USER_NAME}/{REPOSITORY_NAME}.git
git push --set-upstream origin master

Ignore first three lines if it's not a new repository.

Longer description:

Just had the same problem, as non of the above answers helped me, I have decided to post this solution that worked for me.

Few Notes:

  • The SSH key was generated
  • SSH key was added to GitHub, still had this error.
  • I've made a new repository on GitHub for this project and followed the steps described

As the command line toolm I used GitShell (for Windows, I use Terminal.app on Mac).
GitShell is official GitHub tool, can be downloaded from https://windows.github.com/

Upvotes: 2

patthoyts
patthoyts

Reputation: 33223

This is an issue with your stored credentials in the system credential cache. You probably have the config variable 'credential.helper' set to either wincred or winstore and it is failing to clear it. If you start the Control Panel and launch the Credential Manager applet then look for items in the generic credentials section labelled git:https://github.com. If you delete these, then the will be recreated next time but the credential helper utility will ask you for your new credentials.

Upvotes: 1

atomscale
atomscale

Reputation: 111

Here is the simple cause for people who get this error: you are trying to pull from a repo you haven't yet set up your local git to access. For me, I got this error when I changed a public repo to a private one. It's clear to me now that a public repo needs no auth, yet a private one does.

Hope this helps clarify why the error occurs and one potential trigger for that cause.

Upvotes: 0

Akshat Bhuhagal
Akshat Bhuhagal

Reputation: 148

I got the answer by clearing Invalidate caches and then clean build helped me.

  1. Select 'File > Invalidate Caches / Restart' and then click the 'Invalidate and Restart' button.
  2. Select Build > Clean Project and then select Build > Rebuild Project.

Upvotes: 0

Hamid-Ghasemi
Hamid-Ghasemi

Reputation: 294

just check the below

Android Studio -> Preferences -> Version Control -> Git -> Use Credential Helper

Upvotes: 26

danieltan95
danieltan95

Reputation: 860

Tried everything here, didn't work.

However, when I tried to debug via git config --system --list, I got fatal: unable to read config file '/etc/gitconfig': No such file or directory.

So I did the following,

sudo ln -s $HOME/.gitconfig /etc/gitconfig

and voila, it works.

Upvotes: 6

Tony Zampogna
Tony Zampogna

Reputation: 2046

Follow the steps to setup SSH keys here: https://help.github.com/articles/generating-ssh-keys

OR

git remote add origin https://{username}:{password}@github.com/{username}/project.git

Update: If you get "fatal: remote origin already exists." then you have to use set-url:

git remote set-url origin https://{username}:{password}@github.com/{username}/project.git

Upvotes: 136

Peter
Peter

Reputation: 2181

I had this problem in a ssh jail (jailkit), where /dev/tty was not present. I added this device file with jk_cp and the error went away.

Upvotes: 1

Katia
Katia

Reputation: 629

For me nothing worked from suggested above, I use the git pull command from Jenkins Shell Script and apparently it takes wrong user name. I spent ages before I found a way to fix it without switching to SSH.

In your the user's folder create .gitconfig file (if you don't have it already) and put your credentials in following format: https://user:[email protected], more info. After your .gitconfig file link to those credentials, in my case it was:

[credential]
   helper = store --file /Users/admin/.git-credentials

Now git will always use those credentials no matter what. I hope it will help someone, like it helped me.

Upvotes: 15

Neeraj Singh Negi
Neeraj Singh Negi

Reputation: 363

[SSH] executing...
fatal: could not read Username for 'https://github.com': No such device or address

[SSH] completed
[SSH] exit-status: 1

Build step 'Execute shell script on remote host using ssh' marked build as failure
Finished: FAILURE

Sol:- If the repository is private and also it belongs to another person or organisation and you are a contributor of that repository then you can run git commands from Jenkins job and it doesn't prompt you for the username and password.

https://username:token@github.com/accountname/reponame.git

Upvotes: 2

Devendra Vaja
Devendra Vaja

Reputation: 3964

I am using GitHub actions where the jobs are configured to accomplish a task. This solution applies to all the CIs (Jenkins, Travis, Circle) where the git command execution environment changes.

job1: Checkout the repository using the github actions actions/checkout@v2 using the personal access token(PAT), The job completed successfully and repository is cloned.

job2: Fetch the tags using the command git fetch --tags. The job failed with the same error

fatal: could not read Username for 'https://github.com': No such file or directory

Reason of failure: When the job changed, the command running environment also changed, even though the repository exists but the github credentials needs to be provided to fetch the tags.

Solution: add this command before fetching the tags in the job2

git config remote.origin.url 'https://${{ your_personal_access_token }}@github.com/${{ github.repository }}'

Note: ${{ expression }} is the github actions yaml syntex to uncover the environment varibales/ to run expressions.

Upvotes: 3

John Jones
John Jones

Reputation: 2043

Double check the repository URL, Github will prompt you to login if the repo doesn't exist.

I'm guessing this is probably to check if it's a private repo you have access to. Possibly to make it harder to enumerate private repos. But this is all conjecture. /shrug

Upvotes: 0

Kapil Garg
Kapil Garg

Reputation: 1

What worked for me is to change the access of the Git repository from private to public.

Upvotes: -17

Rosdi Kasim
Rosdi Kasim

Reputation: 26026

Note that if you are getting this error instead:

fatal: could not read Username for 'https://github.com': No error

Then you need to update your Git to version 2.16 or later.

Upvotes: 13

Louis Parkin
Louis Parkin

Reputation: 976

I found my answer here:

edit ~/.gitconfig and add the following:

[url "[email protected]:"]
 insteadOf = https://github.com/

Although it solves a different problem, the error code is the same...

Upvotes: 53

Long Tran
Long Tran

Reputation: 83

Earlier when I wasn't granted permission to access the repo, I had also added the SSH pubkey to gitlab. At the point I could access the repo and run go mod vendor, the same problem as your happens. (maybe because of cache)

go mod vendor

go: errors parsing go.mod:
/Users/macos/Documents/sample/go.mod:22: git ls-remote -q https://git.aaa.team/core/some_repo.git in /Users/macos/go/pkg/mod/cache/vcs/a94d20a18fd56245f5d0f9f1601688930cad7046e55dd453b82e959b12d78369: exit status 128:
    fatal: could not read Username for 'https://git.aaa.team': terminal prompts disabled

After a while trying, I decide to remove the SSH key and terminal prompts filling in username and password. Everything is fine then!

Upvotes: 0

Related Questions