You need to change your user.name
and user.email
when you commit.
To do so without affecting your git config, you can set environment variables for a specific commits in order to do that commit "as someone else".
GIT_AUTHOR_NAME="anotherName" GIT_AUTHOR_EMAIL="another@email" \
GIT_COMMITTER_NAME="anotherName" GIT_COMMITTER_EMAIL="another@email" \
git commit -m "commit done as another person"
That will apply only for the current commit.
All the others will be done with the user.name
and user.email
values you see in git config --global --list
.
See the section "Environment Variables" of the git manpage for all the variable you can set.
Another way is to override the config on the git command with the -c
option of the git
command:
git -c user.name="anotherName" -c user.email="another@email" commit -m "..."
(lowercase '-c
', not uppercase '-C
', which is another option)
That is easier to set as an alias, which in Windows is called doskey
:
dokey gituser1=git -c user.name="anotherName" -c user.email="another@email" $*
(the $*
is to get all the othe parameters you will pass to that command)
You would use that as:
gituser1 commit -m "commit done as another person"
I get an error
C:\repo>
GIT_AUTHOR_NAME="Bob" GIT_AUTHOR_EMAIL="bob.smith444.bob@aol.com"
'GIT_AUTHOR_NAME' is not recognized as an internal or external command,
operable program or batch file.
Indeed, Windows shell wouldn't support that syntax directly.
As mentioned in "Setting environment variable for just one command in Windows cmd.exe
", you would need to type:
cmd /C "set GIT_AUTHOR_NAME=\"anotherName\"
&& set GIT_AUTHOR_EMAIL=\"another@email\"
&& set GIT_COMMITTER_NAME=\"anotherName\"
&& set GIT_COMMITTER_EMAIL=\"another@email\"
&& git commit -m \"commit done as another person\""
(one giant line)
NOTE - In windows/cmd, you must remove all the backslashes and the last double quote to make this work.