After installing Git on your machine, the very next step that you must do is configure git username and email address. Git needs these details because it attaches them to every commit that you make. Actually, these details help other developers working in a project to know who has made changes to the code. Without configuring username and email address, you won't be able to run git commit
command and you will get an error.
Note: Email address and username that you provide to Git has nothing to do with GitHub, Bitbucket and GitLab. These details can be different from your GitHub account. The only purpose of configuring them is to help other developers working on the project to contact you if they need to ask anything about the commit.
git config
command is used to add Git identity. In general, you use --global
option to set them globally so that you don't have to set them for each repository.
git config --global user.email "[email protected]" git config --global user.name "Mohit Natani"
Note: You must replace the above details with your name and email address.
The above command saves the details in a ~/.gitconfig
file.
[user] email = [email protected] name = Mohit NataniYou can even view these details by running:
$git config --list [email protected] user.name=Mohit Natani
When you run git config
command without --global
option, you set username and email address for a specific repository.
Go to the repository directory for which you want to set Git identity.
Set repository-specific username and email address:
git config user.email "[email protected]" git config user.name "Mohit Natani"
The above information is saved to .git/config
file.
[user] email = [email protected] name = Mohit Natani
Verify that information you have entered is correct or not:
$git config --list [email protected] user.name=Mohit Natani