Linux 每次我推送时,Git 都会要求输入用户名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11403407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git asks for username every time I push
提问by RanRag
Whenever I try to push into my repo git asks for both username & password
.
每当我尝试进入我的 repo 时,git 都会同时要求username & password
.
I have no problem in re-entering my password each time but the problem is in entering username. I use https
to clone my repository.
我每次重新输入密码都没有问题,但问题在于输入用户名。我https
用来克隆我的存储库。
So, how can I configure git so that it doesn't asks for username
on each git push
.
那么,我如何配置 git 以便它不会username
在每个git push
.
I am new to linux but IIRC in windows git push
only asks for password.
我是 linux 新手,但 Windows 中的 IIRCgit push
只要求输入密码。
采纳答案by Alexander Zhugastrov
Edit (by @dk14 as suggested by moderators and comments)
编辑(由@dk14 由版主和评论建议)
WARNING: If you use credential.helper store
from the answer, your password is going to be stored completely unencrypted ("as is") at ~/.git-credentials
. Please consult the comments section below or the answers from the "Linked" section, especially if your employer has zero tolerance for security issues.
警告:如果您使用credential.helper store
from answer,您的密码将完全未加密(“按原样”)存储在~/.git-credentials
. 请参阅下面的评论部分或“链接”部分的答案,尤其是当您的雇主对安全问题零容忍时。
Even though accepted, it doesn't answer the actual OP's question about omitting a username only (not password). For the readers with that exact problem @grawity's answermight come in handy.
即使被接受,它也没有回答实际的 OP 关于仅省略用户名(不是密码)的问题。对于有这个确切问题的读者,@grawity 的答案可能会派上用场。
Original answer (by @Alexander Zhu):
原始答案(@Alexander Zhu):
You can store your credentials using the following command
您可以使用以下命令存储您的凭据
$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
Also I suggest you to read$ git help credentials
另外我建议你阅读$ git help credentials
回答by RanRag
You can accomplish this in the .git/config
file of your local repository. This file contains a section called 'remote' with an entry called 'url'. The 'url' entry should contains the https link of repository you're talking about.
您可以在.git/config
本地存储库的文件中完成此操作。该文件包含一个名为“remote”的部分,其中包含一个名为“url”的条目。'url' 条目应包含您正在谈论的存储库的 https 链接。
When you prefix the host 'url' with your username, git
shouldn't be asking for your username anymore. Here's an example:
当您用您的用户名作为主机“url”的前缀时,git
不应再询问您的用户名。下面是一个例子:
url = https://[email protected]
回答by gkris
回答by Daniel Lerch
If you are using https instead of ssh, you can edit "url" in .git/config
as user701648 says, but if you want you can add also the password:
如果您使用 https 而不是 ssh,您可以.git/config
像 user701648 所说的那样编辑“url” ,但如果您愿意,还可以添加密码:
url = https://username:[email protected]
回答by Alan De Smet
You can set your username for all repositories at a given site by putting something like the following in your Git configuration file. You'll want to change "https://example.com" and "me" to the actual URL and your actual username.
您可以通过在 Git 配置文件中放置如下内容来为给定站点的所有存储库设置用户名。您需要将“ https://example.com”和“me”更改为实际的 URL 和您的实际用户名。
[credential "https://example.com"]
username = me
(This is directly from "git help credentials")
(这直接来自“git帮助凭证”)
回答by Jay Patel
Permanently authenticating with Git repositories
使用 Git 存储库进行永久身份验证
Run following command to enable credential caching:
运行以下命令以启用凭据缓存:
$ git config credential.helper store
$ git push https://github.com/repo.git
Username for 'https://github.com': <USERNAME>
Password for 'https://[email protected]': <PASSWORD>
Use should also specify caching expire
使用还应指定缓存过期
git config --global credential.helper "cache --timeout 7200"
After enabling credential caching, it will be cached for 7200 seconds (2 hour).
启用凭据缓存后,将缓存7200 秒(2 小时)。
Read credentials Docs
阅读凭据文档
$ git help credentials
回答by Ben
The easiest way I found was with this command:
我找到的最简单的方法是使用以下命令:
git config --global credential.https://github.com.username <your_username>
This works on a site by site basis and modifies your global git config.
这适用于逐个站点并修改您的全局 git 配置。
To see the changes, use:
要查看更改,请使用:
git config --global --edit
回答by Lukasz Czerwinski
Add new SSH keys as described in this article on GitHub.
按照GitHub 上的本文所述添加新的 SSH 密钥。
If Git still asks you for username & password, try changing https://github.com/
to [email protected]:
in remote URL:
如果 Git 仍然要求您输入用户名和密码,请尝试在远程 URL 中更改https://github.com/
为[email protected]:
:
$ git config remote.origin.url
https://github.com/dir/repo.git
$ git config remote.origin.url "[email protected]:dir/repo.git"
回答by Hazarapet Tunanyan
If you use SSHversion, you will not have any problems with passwords.Only one time you generate SSHkey, to tell git, that thispc will work with thisgithub account and never ask me again about any access (for this pc).
如果你使用SSH版本,你不会有任何密码问题。只有一次你生成SSH密钥,告诉 git,这台电脑将与这个github 帐户一起工作,并且永远不会再问我任何访问权限(对于这台电脑)。
回答by Stephen Tun Aung
$ git config credential.helper store
$ git push/push https://github.com/xxx.git
Then enter your user name and password.
- Done
$ git config credential.helper 存储
$ git push/push https://github.com/xxx.git
然后输入您的用户名和密码。
- 完毕