本文翻译自:Git asks for username every time I push

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以便它不会在每个git push上请求username

I am new to linux but IIRC in windows git push only asks for password. 我是linux的新手,但是在Windows git push IIRC只要求输入密码。


#1楼

参考:https://stackoom.com/question/lqXv/Git每次推送时都会询问用户名


#2楼

You can accomplish this in the .git/config file of your local repository. 您可以在本地存储库的.git/config文件中完成此操作。 This file contains a section called 'remote' with an entry called 'url'. 此文件包含一个名为“remote”的部分,其中包含一个名为“url”的条目。 The 'url' entry should contains the https link of repository you're talking about. 'url'条目应包含您正在讨论的存储库的https链接。

When you prefix the host 'url' with your username, git shouldn't be asking for your username anymore. 当您使用您的用户名为主机'url'添加前缀时, git不应该再询问您的用户名。 Here's an example: 这是一个例子:

url = https://username@repository-url.com

#3楼

Make sure that you are using SSH instead of http. 确保使用SSH而不是http。 Check this SO answer. 检查这个 SO答案。


#4楼

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 . 警告:如果您使用了答案中的credential.helper store ,则您的密码将以~/.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. 请参阅下面的评论部分或“链接”部分的答案,特别是如果您的雇主对安全问题的容忍度为零。

Even though accepted, it doesn't answer the actual OP's question about omitting a username only (not password). 即使被接受,它也没有回答实际OP关于省略用户名(不是密码)的问题。 For the readers with that exact problem @grawity's answer might come in handy. 对于那些确切问题的读者来说,@ 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


#5楼

如果您使用的是https而不是ssh,则可以在.git/config编辑“url”,如user701648所示,但如果您需要,还可以添加密码:

url = https://username:password@repository-url.com

#6楼

You can set your username for all repositories at a given site by putting something like the following in your Git configuration file. 您可以通过在Git配置文件中添加以下内容,为给定站点的所有存储库设置用户名。 You'll want to change " https://example.com " and "me" to the actual URL and your actual username. 您需要将“ https://example.com ”和“我”更改为实际网址和实际用户名。

[credential "https://example.com"]username = me

(This is directly from "git help credentials") (这直接来自“git help credentials”)

Git每次推送时都会询问用户名相关推荐

  1. github每次推送都要输入用户名和密码

    /****************************************************************************** github每次推送都要输入用户名和密码 ...

  2. 使用git push推送时出现错误error: failed to push some refs to ‘https://gitee.com/yang-yimu/vue_shop.git‘

    解决方案:可能是因为在git线上仓库中,手动删除了某个文件导致线上线下不同步,这种情况下需要先git pull --rebase origin master 拉取线上仓库,在使用git add ,gi ...

  3. 将本地的Git仓库推送到远程仓库的两种方式

    一.远程仓库的地址有两种形式: https协议仓库地址:https://github.com/用户名/仓库名.git ssh协议仓库地址:git@github.com/用户名/仓库名.git 如何利用 ...

  4. Git远程推送和抓取分支

    查看远程库信息 当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin. 要查看远程库的信息,用git remote, ...

  5. Win10任务计划+PowerShell实现Git自动推送

    Win10任务计划+PowerShell实现自动推送远程仓库 前言 1. AutoPush.sp1 2. taskschd.msc 前言 每次写完代码都要推送到Gitee太麻烦了 就写了一个Power ...

  6. git强制推送_Git 常用命令

    Git 常用命令总结 1. GIT 工作区 add commitworking directory ------- index(stage) ---------- HEAD | | | | | | 工 ...

  7. git 代码推送流程_Git 101:一个让您开始推送代码的Git工作流程

    git 代码推送流程 I'm going to explain Git the way I wish someone had explained to me back when I was first ...

  8. git push git pull 推送/拉取分支

    git push与git pull是一对推送/拉取分支的git命令.  git push 使用本地的对应分支来更新对应的远程分支. <code class="hljs xml has- ...

  9. git命令推送本地到远程分支

        目录 git命令推送本地到远程分支 1.从命令行创建一个新的仓库 2.从命令行推送已经创建的仓库 3.删除远程 Git 仓库 fetch -p 修剪远程分支 Git复制已有分支到新分支开发 g ...

最新文章

  1. Java 过滤特殊字符的 正则表达式
  2. Linux下安装rlwrap
  3. 如何用C语言编写wav读取函数,C++读取WAV音频文件的头部数据的实现方法
  4. Android 视频播放器 VideoView 的使用,播放本地视频 和 网络 视频
  5. Golang——Json的序列化和反序列化
  6. robotframework自动化测试修炼宝典_自动化测试之框架Cucumber和RobotFramework的实战对比...
  7. Java内存模型三大特性
  8. 全新 HTML 5.1 工作草案发布
  9. php+system+info_systeminfo命令详解
  10. Opmanager研究笔记
  11. 天眼查是怎么获得企业工商信息的?
  12. 数字化到底有什么用?
  13. apache ii评分怎么评_APACHE II评分表
  14. python读书心得体会范文_读书心得体会600字_关于读书的心得体会范文(3篇)
  15. Educational Codeforces Round 100 A—D题题解
  16. 蒲公英内侧:项目打包成ipa文件,创建证书和描述文件流程
  17. 如何查看MySql的安装位置?
  18. 在Python中使用Turtle库画“蜂窝状六边形”
  19. 云适配联合IT巨头拟成立“中国企业级HTML5产业联盟”
  20. 电脑修改默认远程端口3389的方法(☆亲测)

热门文章

  1. 自己动手实现OpenGL-OpenGL原来如此简单(三)
  2. Android stadio litepal
  3. android蓝牙音乐之AVRCP介绍和使用
  4. Socket 通信原理(Android客户端和服务器以TCPUDP方式互通)
  5. 2019年,智慧零售是如何影响零售行业?
  6. Java8新特性学习记录
  7. (011) java后台开发之泛型类
  8. mysql 求数据的长度_mysql 如何求数据的长度
  9. rs485协议_你知道HART和RS485协议的区别吗?
  10. 展开被 SpringBoot 玩的日子 《 二 》 WEB 开发