git - 如何将 "git push"转到私有(private)存储库并提示输入用户名和密码?

标签 git github

我克隆了我的私有(private) Github存储库到我的 CentOS 6 机器(git 版本 1.7.1)。我能否以某种方式设置我的本地 git 存储库以在输入 git push 时始终提示输入用户名和密码?

不会总是使用相同的用户名。

Private repository

$ 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/

相关文章:

git - 如何删除没有本地跟踪分支的远程分支?

git - 如何在 mplab.x 上集成 git

git - Visual Studio 解决方案与 Git 项目和 TFS 项目混合

git - 将本地 git 获取到新的 github 存储库时出错

mysql - 无法使用 gitlab-ci.yml 连接到 MySql

git - 有没有办法从 master 中检查出落后于许多 Git 提交的单个文件?

git - 当 git revert 中止并显示错误消息时我该怎么办?

github - 如何防止非贡献者看到公共(public) GitHub 存储库中的特定文件?

node.js - "section"在 github : what does it mean?

Git 卡在写对象上