5

I am aware that I can use git config credential.helper to store both my username and password. But I want to ONLY store my username and have the terminal ask for my password each time I push. How is this done?

Something similar to this, but without the password.

$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
2
  • this might help you git-scm.com/docs/gitcredentials
    – dippas
    Commented Feb 3, 2019 at 20:38
  • As far as a literal answer to the question, I would second brian m carlson's answer below. (I was writing a similar answer, but am not where I can test to verify it, and couldn't find appropriate documentation references to back it up for protocols other than ssh. But as it seems to be an answer several are coming to, I trust that it's right.) That said: I'm curious why you want to do it this way? Compared to a proper no-password-entry solution, this is less secure in practice Commented Feb 4, 2019 at 2:06

1 Answer 1

7

Git credential helpers store both usernames and passwords. The design is such that if a username and password combination succeed, then the helper is told to write both items to its store.

If you want to store only the username, and not the password, then you shouldn't use a credential helper. Instead, you should disable the credential helper and write the username in the URL for the remote. For example, you can use git remote set-url origin http://[email protected]/repo.git to set the remote URL for origin to contain your username. Note that if your username contains characters outside of letters and numbers, it may need to be percent-escaped.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.