git提交的时候需要用户名和密码

        帮一个C#的哥们从SVN转到了Git,算是好事一件了。通过keygen生成和配置了公钥,也配置到了remote端,安装好了sourceTree,checkout出代码就可以工作了。

        昨天他说碰到一个问题,从命令行每次提交或者同步代码的时候都需要输入用户名和密码,感觉有点麻烦,让我帮忙看一看。我检查了.ssh/id_rsa.pub和远程配置的一样,通过ssh命令也可以和远程通讯,比如:

PTY allocation request failed on channel 0
Coding.net Tips : [Hello XXX! You've connected to Coding.net by SSH successfully! ]
Connection to coding.net closed.

那问题出在哪里呢?查看一下配置,git config -l如下:

  

ore.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://git.coding.net/XXX/storesystem.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

      看来clone的时候是使用的https,而不是ssh,所以配置的SSH是没有用得,需要改变一下remote.origin到SSH就可以了:

   

git remote remove origin
git remote add origin [email protected]:XXX/storesystem.git

git branch --set-upstream-to=origin/master master

       这样,就是使用SSH的方式了。使用git pull或者git push都可以不用输入用户名和密码了。比较了github和Coding,发现github提供了SSH和https的clone地址,而coding只提供了https的地址。这算不算是个问题呢?

猜你喜欢

转载自david-je.iteye.com/blog/2221881