Git - could not read Username for 'https://github.com',push报错解决办法

时间:2021-08-26 16:46:37

执行git push命令异常,如下:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v --tags --set-upstream origin refs/heads/master:refs/heads/master
Pushing to https://github.com/gongyuhonglou/PlaylistVaporServer_Swift.git
fatal: could not read Username for 'https://github.com': Device not configured
Completed with errors, see above

原因:

.git文件下     config文件中url/pushurl没有用户身份信息:

[core]
repositoryformatversion =
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/gongyuhonglou/PlaylistVaporServer_Swift.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = https://github.com/gongyuhonglou/PlaylistVaporServer_Swift.git
[branch "master"]
remote = origin
merge = refs/heads/master

解决:

在请求串中加入身份信息即可,格式为:

https://[userName]:[password]@github.com/[username]/project.git

修改后:

[remote "origin"]
url = http://gongyuhonglou:000000@github.com/gongyuhonglou/PlaylistVaporServer_Swift.git
fetch = +refs/heads/*:refs/remotes/origin/*

注:000000代表密码

如果还是不能解决的话,就在终端操作git push:(提示手动输入github账号和密码)

macdeMacBook-Pro:Vapor mac$ git push
Username for 'https://github.com': github账号
Password for 'https://wengrp@yeah.net@github.com': github密码
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.