You need to set who you are *before* creating any commit. That will allow commits to have the right author name and email associated to them.
It has nothing to do with authentication when pushing to a remote repository (e.g. when pushing to a remote repository using your GitHub, BitBucket, or GitLab account)
To declare that identity for all repositories, use
git config --global
This will store the setting in your user's
.gitconfig file: e.g.
$HOME/.gitconfig or for Windows,
git config --global user.name "Your Name" git config --global user.email email@example.com
To declare an identity for a single repository, use
git config inside a repo.
This will store the setting inside the individual repository, in the file
cd /path/to/my/repo git config user.name "Your Login At Work" git config user.email firstname.lastname@example.org
Settings stored in a repository's config file will take precedence over the global config when you use that repository.
Tips: if you have different identities (one for open-source project, one at work, one for private repos, ...), and you don't want to forget to set the right one for each different repos you are working on:
Remove a global identity
git config --global --remove-section user.name git config --global --remove-section user.email
To force git to look for your identity only within a repository's settings, not in the global config:
git config --global user.useConfigOnly true
That way, if you forget to set your
user.email for a given repository and try to make a commit, you will see:
no name was given and auto-detection is disabled no email was given and auto-detection is disabled