Git Getting started with Git Setting your user name and email


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, %USERPROFILE%\.gitconfig.

git config --global "Your Name"
git config --global

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 $GIT_DIR/config. e.g. /path/to/your/repo/.git/config.

cd /path/to/my/repo
git config "Your Login At Work"
git config

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
    git config --global --remove-section
  • 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 and 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