&引用;git配置-l“文件”;显示我的用户名/电子邮件集,但git push要求输入用户名

&引用;git配置-l“文件”;显示我的用户名/电子邮件集,但git push要求输入用户名,git,github,Git,Github,鉴于我的电子邮件和用户名包含在~/.gitconfig中: $cat ~/.gitconfig [user] name = MyFirst MyLast email = myemail@gmail.com 和git config-l“看到”它们: 为什么git-push看不到它们 $git push origin master Username for 'https://github.com': 这里有更多的信息: 地位: git status On branch mas

鉴于我的电子邮件和用户名包含在~/.gitconfig中:

$cat ~/.gitconfig
[user]
    name = MyFirst MyLast
    email = myemail@gmail.com
和git config-l“看到”它们:

为什么
git-push
看不到它们

 $git push origin master
Username for 'https://github.com': 
这里有更多的信息:

地位:

git status
On branch master
Your branch is based on 'origin/master', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)
Untracked files:
  (use "git add <file>..." to include in what will be committed)
git状态
论分行行长
您的分支基于“源代码/主代码”,但上游已消失。
(使用“git branch--unset upstream”进行修正)
未跟踪的文件:
(使用“git add…”包含在将提交的内容中)
遥控器:

git remote -v
origin  https://github.com/<owner>/<repo> (fetch)
origin  https://github.com/<owner>/<repo> (push)
git远程-v
起源https://github.com// (取回)
起源https://github.com// (推)
这是两个完全不同的数据部分,它们不相关

配置中的用户名用于设置提交的作者

当您在按遥控器时被提示输入用户名时,情况有所不同。这些是身份验证凭据

Git不假定配置的用户名与身份验证凭据用户名相同

这是一件好事。例如,一个非常真实的例子:

我的在Git中配置的用户名
Thomas Stringer

我的GitHub用户名
tstringer


如果假设是这样的话,那么我不得不重写或重新配置将非常恼人。

这更多的是对@Thomas Stringer的答案(将被接受)的评论/补充:

处理这个问题的方法是使用ssh(结合~/.ssh/config)

git远程设置url源ssh://git@github.com//

Git不会假定您在
~/.gitconfig
中的名字与您的github用户名相同。git软件与github网站是分开的。我建议将SSH密钥添加到您的github帐户,这样您就不必在每次推送时都输入用户名/密码。是的,我总是忘记使用SSH(与~/.SSH/config一起使用)<代码>git远程设置url源ssh://git@github.com/
git remote -v
origin  https://github.com/<owner>/<repo> (fetch)
origin  https://github.com/<owner>/<repo> (push)
git remote set-url origin ssh://git@github.com/<owner>/<repo>