Question:
I am trying to commit to a project on github.com from my work laptop, which is already configured for the company git server. Is there a way to commit specifying different author credentials, possible using a different configuration file or orther command line switches?
I’ve tried using
1 2 |
--author="My Name |
and I received the message:
1 2 3 4 5 6 7 8 9 10 11 12 |
Committer: unknown Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly: git config --global user.name "Your Name" git config --global user.email you@example.com After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author |
but it still didn’t update my username for committing to the github.com project. Is there anything else I can try and is it even possible?
Answer:
First, the author is not necessarily the same as the committer. Git tracks both.
To set what name to use for just this repository, you could do:
1 2 3 |
git config user.name "Your Name" git config user.email "Your email" |
Notice the absence of the --global
option. This will set the configuration in this repository only.
Alternatively, you can do this for only a single command, using the -c
option:
1 2 |
git -c "user.name=Your Name" -c "user.email=Your email" commit ... |
But I think it’s better to just use the config options above.