setting credentials just for the first time (libgit2)

我们两清 提交于 2019-12-12 04:31:38

问题


So I use some libgit2 functions to connect to the remote and perform git push. I want to push to private repository, so I have to set credentials.

But for example, when I work with private repositories via git commands and I want to connect for the first time to this repository, I enter credentials...but after that, if I want to push for the second, third time or so, I don't have to write that credentials again, also when I restart computer. It seems to me that there is some place where "known repositories" are stored with their credentials.

And my question is, is there a way how to do that with libgit2? I mean, is there a way how to push to "known" private remote repositories without setting credentials? "Known" means repositories which I already worked with so I have already set credentials

I want to work with many different repositories, each of these repositories have their own credentials so I don't want to set credentials manually everytime I push.

When I perform push without setting credentials(push to "known" repo), this error message is displayed

Request failed with status code: 401

So is there a way, how not to set credentials every time I push?


回答1:


Command line git has a set of credential helpers that securely store credentials using native platform APIs. There are credential helpers that use Keychain on Mac, Windows Credential Manager on Windows, and gnome-keyring and libsecret on Linux. See the chapter on credential helpers in the git book for more information.

Libgit2 does not have a similar abstraction for securely storing passwords. Perhaps it should. Instead your application can adapt the different native APIs to store passwords then provide them to the libgit2 credential callback based on the username and hostname parameters.



来源:https://stackoverflow.com/questions/44156840/setting-credentials-just-for-the-first-time-libgit2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!