git向github提交時不輸入賬號密碼


緣由:每次向github提交代碼時都要輸入用戶名密碼,太麻煩了,影響效率

解決方案:

方案一:

在你的用戶目錄下新建一個文本文件.git-credentials

  • Windows:C:/Users/username
  • Mac OS X: /Users/username
  • Linux: /home/username

注意:鼠標右鍵新建文件重復命名是成功不了的,需要借助Sublime等IDE工具來創建文件。

.git-credentials在文件中輸入以下內容:

https:{username}:{password}@github.com

{username}和{password}是你的github的賬號和密碼

修改git配置
執行命令:

git config --global credential.helper store

上述命令會在.gitconfig文件(.gitconfig與.git-credentials在同目錄下)末尾添加如下配置:

  [user]
  	email = xxx@163.com
  	name = xxx
  [credential]
  	helper = store

經過上述三步配置之后, 你push代碼到github時, 便無需再輸入用戶名密碼了。

方案二:

  1. 在命令行輸入命令:

    git config --global credential.helper store

這一步會在用戶目錄下的.gitconfig文件最后添加:

[credential]
	helper = store
  1. push 代碼

push你的代碼 (git push), 這時會讓你輸入用戶名和密碼, 這一步輸入的用戶名密碼會被記住, 下次再push代碼時就不用輸入用戶名密碼!這一步會在用戶目錄下生成文件.git-credential記錄用戶名密碼的信息。

總結:
方案一與方案二都是創建.git-credential文件並寫入用戶信息,一個是手動創建,一個命令創建。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM