2013-04-26 89 views
1

我正在研究git repo(gitolite)配置爲只允許我訪問https的項目。更糟糕的是,他們爲我創建的用戶名是可怕的。在我的.git/config中,我將user.name設置爲我的真實姓名,以便我的提交與我正確關聯。然而,無論何時我推或拉,我都必須記住並正確地輸入(隱藏少一些!)我可怕的認證用戶名。我想在我的本地git倉庫配置中設置我的auth用戶標識。GIT over HTTP配置授權用戶名。 credential.username不起作用?

http://git-scm.com/docs/git-confighttp://git-scm.com/docs/gitcredentials.html,我試圖

git config credential.username <bletcherous-name> 

git config credential.https://git-server.myco.com.username <bletcherous-name> 

但這些都沒有效果。當我連接時,我仍然被提示輸入用戶名。

最終我確實發現我可以做到以下幾點。但似乎下面是一個黑客,上述應該已經工作。任何想法我做錯了什麼?

git remote rm origin 
git remote add origin https://[email protected]/git/my-repo.git 

回答

1

總結:

git config --local credential.https://git-server.myco.com.username bletcherous-name 

這裏展示一下這個和其他類似的東西做的Git的配置文件外殼成績單,所以你可以(我喜歡)只是直接編輯配置文件。

[email protected]:~$ mkdir foo 
[email protected]:~$ cd foo 
[email protected]:~/foo$ git init 
Initialized empty Git repository in /home/localuser/foo/.git/ 
[email protected]:~/foo$ cat .git/config 
[core] 
repositoryformatversion = 0 
filemode = true 
bare = false 
logallrefupdates = true 
[email protected]:~/foo$ git remote add origin https://[email protected]/git/my-repo.git 
[email protected]:~/foo$ cat .git/config 
[core] 
repositoryformatversion = 0 
filemode = true 
bare = false 
logallrefupdates = true 
[remote "origin"] 
url = https://[email protected]/git/my-repo.git 
fetch = +refs/heads/*:refs/remotes/origin/* 
[email protected]:~/foo$ git remote rm origin 
[email protected]:~/foo$ git remote add origin https://git-server.myco.com/git/my-repo.git 
[email protected]:~/foo$ cat .git/config 
[core] 
repositoryformatversion = 0 
filemode = true 
bare = false 
logallrefupdates = true 
[remote "origin"] 
url = https://git-server.myco.com/git/my-repo.git 
fetch = +refs/heads/*:refs/remotes/origin/* 
[email protected]:~/foo$ git config --local credential.https://git-server.myco.com.username bletcherous-name 
[email protected]:~/foo$ cat .git/config 
[core] 
repositoryformatversion = 0 
filemode = true 
bare = false 
logallrefupdates = true 
[remote "origin"] 
url = https://git-server.myco.com/git/my-repo.git 
fetch = +refs/heads/*:refs/remotes/origin/* 
[credential "https://git-server.myco.com"] 
username = bletcherous-name 
[email protected]:~/foo$