问题
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.
回答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 HTTPS URLS
- no credential helper
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.
来源:https://stackoverflow.com/questions/58035315/set-git-to-always-prompt-for-credentials