2

我正在开发一个项目,其中 git repo (gitolite) 被配置为只允许我访问 https。更糟糕的是,他们为我创建的用于验证的用户名非常糟糕。在我的 .git/config 中,我将 user.name 设置为我的真实姓名,以便我的提交正确地与我相关联。但是,每当我推或拉时,我都必须记住并正确输入(仍然隐藏!)我可怕的身份验证用户名。我想在我的本地 git repo 的配置中设置我的身份验证用户 ID。

根据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://bletcherous-name@git-server.myco.com/git/my-repo.git
4

1 回答 1

1

总之:

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

这是一个 shell 脚本,显示了此操作和其他类似操作对 Git 配置文件的作用,因此您可以(如我所愿)直接编辑配置文件。

localuser@localhost:~$ mkdir foo
localuser@localhost:~$ cd foo
localuser@localhost:~/foo$ git init
Initialized empty Git repository in /home/localuser/foo/.git/
localuser@localhost:~/foo$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
localuser@localhost:~/foo$ git remote add origin https://bletcherous-name@git-server.myco.com/git/my-repo.git
localuser@localhost:~/foo$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://bletcherous-name@git-server.myco.com/git/my-repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
localuser@localhost:~/foo$ git remote rm origin
localuser@localhost:~/foo$ git remote add origin https://git-server.myco.com/git/my-repo.git
localuser@localhost:~/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/*
localuser@localhost:~/foo$ git config --local credential.https://git-server.myco.com.username bletcherous-name
localuser@localhost:~/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
localuser@localhost:~/foo$
于 2013-09-26T05:58:44.280 回答