So, you installed Git on your system, cloned a Git repo, made some changes and now want to commit your changes.
The problem is that you are probably seeing an error like when you try to add a commit:
Author identity unknown
*** Please tell me who you are.
git config --global user.email "[email protected]"
it 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 '[email protected](none)')
The reason and solution are both mentioned in the error message.
You don't have git username and email set and hence it asks you to set it up first using the given commands.
Let's see how to do that.
Set up git username and email
All git commits must have a username and email address. That's how it is built to give a collaborative environment where each change can be identified. Thus the username and email become necessary.
Git allows username and email to set up at two levels:
- Global level: All commits in all project repositories (opt for this is you are unsure)
- Repo level: The username and email is valid only for the current repository
Now, how do you set it up? It's simple.
Use the following command to set up the global username:
git config --global user.name "Your Username"
You have to replace
Your Username with your own username, of course.
Similarly, use the following command to set up the global email address:
git config --global user.email [email protected]
Note that it doesn't have to be an actual email address. You may use a fake name and email address, however, it is a good practice to use a real email address so that your commits can be identified (if you are contributing to public repositories).
At any point in time, you can see your Git settings with:
git config --list
--globalwhile setting it up from within the repository.
Bonus tip: Change Git username and email
Want to change your git username and email? It's quite simple.
Just do what you did earlier to set up the username and email. That's it.
Check what you have:
git config --list
And then change it:
git config --global user.name "Your Username" git config --global user.email [email protected]
Simple, right? Enjoy it :)