Azure Devops requiring password every time I push from local to remote repository

时间:2019-01-18 18:23:34

标签: git continuous-integration azure-devops continuous-deployment

Relatively new git and azure-devops user here.

I am currently working on a project locally that I wish to push to my private azure-devops repository called 'Hello_World'.

So locally, I did the following:

git remote add origin https://dkennetz@dev.azure.com/dkennetz/Hello_World/_git/Hello_World

Then I wanted to push all my local code to the remote repo, so I simply did:

git push -u origin --all

and I was prompted:

[dkennetz@nodecn204  Hello_World]$ git push -u origin --all
Password for 'https://dkennetz@dev.azure.com':

Which is fine. I entered the token the first time and I thought all things would be handled accordingly for future pushes. I was wrong. Every time after this, I still have to enter my password for pushes.

I am doing this as a simple test case to try out azure-devops but I can see this becoming a serious issue if each user in a project has to enter username and password for CI/CD every time a user wants to push code to a repo.

I thought maybe I could add something to my config to handle this, but I am not sure.

If I run:

git config --list

I get (the space is because of code formatting issues):

user.name=Dennis Kennetz
user.email=funkyman@funky.org
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

remote.origin.url=https://dkennetz@dev.azure.com/dkennetz/Hello_World/_git/Hello_World

remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

Thanks for the help!

1 个答案:

答案 0 :(得分:0)

花了一些时间后,我找到了一个对我有用的解决方案(尽管它将您的令牌以纯文本格式存储在您的git凭据中)。

在推送到您的仓库之前,输入以下内容:

git config --global credential.helper 'cache --timeout=3600'

这将在转储之前将所有用户名和密码存储在您的配置中3600秒。您可以将超时时间修改为会话的长度,也可以不设置超时时间以无限期存储。

这样,您只需要键入一次令牌,令牌就会存储直到达到持续时间为止,此时您将不得不再次键入令牌。