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 dir
For those getting this error in a Jenkins pipeline, it can be fixed by using an SSH Agent plugin. Then wrap your git commands in something like this:
sshagent(['my-ssh-key']) {
git remote set-url origin git@github.com:username/reponame.git
sh 'git push origin branch_name'
}
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
Try using a normal Windows shell such as CMD.
I found my answer here:
edit ~/.gitconfig
and add the following:
[url "git@github.com:"]
insteadOf = https://github.com/
Although it solves a different problem, the error code is the same...
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.
Replace your remote url like this:
git remote set-url origin https://<username>@github.com/<username>/<repo>.git