我克隆了我的私有(private) Github存储库到我的 CentOS 6 机器(git 版本 1.7.1)。我能否以某种方式设置我的本地 git 存储库以在输入 git push
时始终提示输入用户名和密码?
不会总是使用相同的用户名。
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://github.com/USER/PRIVATE-REPO.git
[branch "master"]
remote = origin
merge = refs/heads/master
当我现在执行 git push
时,我得到了这个:
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/Industriromantik/render-linux.git/info/refs
fatal: HTTP request failed
如果我执行以下命令,则推送成功:
git push https://MY-GITHUB-USERNAME@github.com/USER/PRIVATE-REPO
...但是,如果可能的话,我只想执行 git push
并提示输入 用户名和密码。
最佳答案
使用 https://
$ git clone https://github.com/user/private-repo.git/
因为(看起来)https 连接不缓存密码(也不缓存用户名,除非你在 URL 中给出),git 总是会要求你输入密码(和用户名):
$ git push
Username for 'https://github.com': USER
Password for 'https://USER@github.com': ****
$
关于git - 如何将 "git push"转到私有(private)存储库并提示输入用户名和密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33766650/