2

Due to some specialized hardware, we have one machine that is shared with a few developers. I would like git commits and pushes to always prompt for credentials. I've tried a couple fixes found on SO including git config --global --unset credential.helper as well as editing the config to include askpass = under [core]. After doing both of these, I still get this when I try to commit:

PS C:\Projects\Windows\projectname> git commit -m "testing shared credentials"

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'user@pcname.(none)')

I don't want to set a default identity. I want it to literally ask for a username and password every time. Is this possible?

Edit: I would be okay with perhaps setting a default identity of "Generic Developer" or something but still prompting for credentials.

  • Possible duplicate of [Git: force user and password prompt](https://stackoverflow.com/questions/14643308/git-force-user-and-password-prompt). – EternalHour Sep 20 '19 at 21:51
  • @EternalHour This is perhaps not a dup. The OP confuses credentials (login/password) with identification (user name/email which have nothing with authentication). – phd Sep 20 '19 at 23:40
  • 1
    @phd - That's why I didn't cast a close vote. Looking at it now, the issue seems to be configuration of `user.email`. – EternalHour Sep 20 '19 at 23:47
  • 1
    I recommend each developer to have their own clone of the code, even if it is the same machine or account. Then set credientials locally on each clone. – hyde Sep 21 '19 at 09:15
  • I may have confused authentication and identity in the post, but I don't want *either* to be retained. –  Sep 23 '19 at 13:44
  • Separate clones for each dev is an interesting workaround. I'll consider it, thanks for the idea. –  Sep 23 '19 at 13:52
  • Again, I have edited the answer to propose a way where the identity is *not* retained. – VonC Sep 24 '19 at 04:19

1 Answers1

-1

I want it to literally ask for a username and password every time. Is this possible?

Regarding identity

See "How do I make git block commits if user email isn't set?"

git config --global user.useConfigOnly true

(With Git 2.21, that works better with git stash too)

That will make Git ask for user.name/email on every commit as long as you don't set a global or local user name/email.

Then, for each commit, you can specify it on the command-line (that will apply for that commit only)

git -c user.name="My Name" -c user.email=my@email.com commit -m "my new commit"

Once the commit done, any new commit would ask for your user name/email again.
Forcing you to specify them on each commit, as show above.

I would be okay with perhaps setting a default identity of "Generic Developer" or something

That is a dreadful idea: you do want to know who did what on each commit.

If have had to develop recently a git wrapper precisely to force a user, on his/her first git command, to select his/her name/email, and store that in a /tmp/git.xxx file, with xxx being the process id of the current bash.
That way, the same wrapper is able to set the proper author/email for each subsequent git commands done in the same shell session (by, presumably, the same user)


Regarding password (authentication)

Make sure to use:

An Git will ask for username/password on every push/pull.
I do confirm that, is there is no credential caching in place, and is HTTPS is used for the remote repository URL (not SSH), a prompt will take place for every pull/push/clone operation.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • "But once you have set an identity for that repo, it won't ask again." This is not what I want. Sorry. –  Sep 23 '19 at 13:44
  • @ScottBeeson OK. I have rewritten/amended the answer to force Git to ask you user.name/email on *every* commit. – VonC Sep 23 '19 at 13:51
  • The "no credential helper" question you linked I had already tried. As you see in the comments to the accepted answer, it either doesn't work anymore or for everyone. –  Sep 24 '19 at 14:14
  • @ScottBeeson The first part of the answer does address your original question, no? – VonC Sep 24 '19 at 14:20
  • No, because I want it to *prompt*. I don't want to force devs to change their commit commands to something so clunky on a single box. –  Sep 24 '19 at 19:11
  • @ScottBeeson That, to my knowledge, won't happen for identity: you have seen the extent of a Git notification for user.name/email in the message you have posted. It does happen with authentication, provided you are using an HTTPS URL and no credential helper: it will prompt for username/password every time. – VonC Sep 24 '19 at 20:20
  • I updated the question a bit. I might be okay with a default *identity* as long as it prompts for *credentials*. I'll think about it and test. –  Sep 24 '19 at 20:23
  • @ScottBeeson OK. That is indeed an *entirely* different question. – VonC Sep 24 '19 at 20:24
  • It's not entirely different... I may have slightly confused identity with credentials, but the question title and opening sentence are very clear and have consistently related to credentials. Sorry. –  Sep 24 '19 at 20:25
  • @ScottBeeson considering identity and authentication are *entirely* different, I confirm the nature of your change in the question. Let me update my answer (again). – VonC Sep 24 '19 at 20:26