2012-01-12 3638 views
30

我在Windows 7上使用git bash。我們使用github作爲我們的資源庫。用git bash配置用戶名和密碼

每當我推或拉我必須提供用戶和密碼憑據。我知道我的SSH密鑰設置正確,否則我將無法訪問存儲庫。 (也就是說,一旦我輸入憑據推/拉正常工作。)

我已經進入

git config --global user.name myusername 
git config --global user.email myemail 
git config --global github.user myusername 
git config --global github.token mytoken 

但無論如何我被要求對每一次我推/拉憑據。

+2

看看... http://stackoverflow.com/questions/5343068/is-there-a-way-to-skip-password-typing-when-using- https-github – SteveC 2013-05-28 15:18:16

回答

37

確保您使用ssh url作爲github repo而不是https url。當您使用https而不是SSH時,它會詢問用戶名和密碼。您可以檢查文件.git/config或運行git config -egit remote show origin以驗證網址並在需要時進行更改。

+7

由於內部防火牆規則,我無法使用SSH(不要問...)還有另一種讓git自動登錄的方法嗎? – Jorn 2015-04-20 09:04:26

0

嘗試使用ssh-agent安裝SSH密鑰以便與git一起使用。它應該在使用密碼後自動登錄。

8

從混帳的bash我喜歡運行命令:

git config --global credential.helper wincred 

在這一點上運行如下命令git pull並輸入您的憑據一次應該有它的儲存以備將來使用。 Git有一個內置的憑證系統,可以在不同的操作系統環境中工作。你可以在這裏得到更多的細節:https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage

+0

這對我有幫助,但解釋了爲什麼以及它的作用可能有用。謝謝你:) [來自help.github的鏈接](https://help.github.com/articles/caching-your-github-password-in-git/) – Casper 2017-12-07 19:38:59