Commit Without Setting User Name and Email

I try to commit like this:

git commit --author='Paul Draper <[email protected]>' -m 'My commit message'

but I get:

*** Please tell me who you are.

Run

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

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

I can set these, but I am on a shared box, and I would have to (want to) unset them afterwards:

git config user.name 'Paul Draper'
git config user.email '[email protected]'
git commit -m 'My commit message'
git config --unset user.name
git config --unset user.email

That's a lot of lines for one commit!

Is there shorter way?


(This occurred to me after suggesting the long version with the environment variables—git commit wants to set both an author and a committer, and --author only overrides the former.)

All git commands take -c arguments before the action verb to set temporary configuration data, so that's the perfect place for this:

git -c user.name='Paul Draper' -c user.email='[email protected]' commit -m '...'

So in this case -c is part of the git command, not the commit subcommand.


You can edit the .git/config file in your repo to add the following alias :

[alias]
  paulcommit = -c user.name='Paul Draper' -c user.email='[email protected]' commit

or you can do this by command line :

git config alias.paulcommit "-c user.name='Paul Draper' -c user.email='[email protected]' commit"

And then you can do :

git paulcommit -m "..."

Remarks:

  • The idea is then to add also aliases like jeancommit, georgecommit, ... for the other users of this shared box.
  • You can add this alias to your global config by editing your personal .gitconfig or by adding --global option to the command line when adding the alias.
  • The alias paulcommit is not a short one, but it is verbose and you can in general type only git pau+tab.