Skip to main content

Setting your commit email address

You can set the email address that is used to author commits on GitHub.com and on your computer.

About commit email addresses

GitHub uses your commit email address to associate commits with your account on GitHub.com. You can choose the email address that will be associated with the commits you push from the command line as well as web-based Git operations you make.

For web-based Git operations, you can set your commit email address on GitHub.com. For commits you push from the command line, you can set your commit email address in Git.

Any commits you made prior to changing your commit email address are still associated with your previous email address.

Note: 您无法验证可用电子邮件地址服务中的电子邮件地址(允许您使用在一段时间后过期的临时地址接收电子邮件的服务)。 如果要将个人电子邮件地址保密,可以使用 GitHub 提供的 noreply 电子邮件地址。 有关详细信息,请参阅“在 GitHub 上设置提交电子邮件地址”。

If you'd like to keep your personal email address private, you can use a noreply email address from GitHub as your commit email address. To use your noreply email address for commits you push from the command line, use that email address when you set your commit email address in Git. To use your noreply address for web-based Git operations, set your commit email address on GitHub and choose to Keep my email address private.

You can also choose to block commits you push from the command line that expose your personal email address. For more information, see "Blocking command line pushes that expose your personal email."

To ensure that commits are attributed to you and appear in your contributions graph, use an email address that is connected to your account on GitHub.com, or the noreply email address provided to you in your email settings. For more information, see "Adding an email address to your GitHub account."

Note: If you created your account on GitHub.com after July 18, 2017, your noreply email address for GitHub is an ID number and your username in the form of ID+USERNAME@users.noreply.github.com. If you created your account on GitHub.com prior to July 18, 2017, your noreply email address from GitHub is USERNAME@users.noreply.github.com. You can get an ID-based noreply email address for GitHub by selecting (or deselecting and reselecting) Keep my email address private in your email settings.

If you use your noreply email address for GitHub to make commits and then change your username, those commits will not be associated with your account on GitHub.com. This does not apply if you're using the ID-based noreply address from GitHub. For more information, see "Changing your GitHub username."

Setting your commit email address on GitHub

如果尚未启用电子邮件地址隐私保护,则在 GitHub 上编辑、删除或创建文件或者合并拉取请求时,可以选择将作者更改提交到哪个经验证的电子邮件地址。 如果启用了电子邮件地址隐私,则不能更改提交作者电子邮件地址,默认情况下是 <username>@users.noreply.github.com

  1. 在任何页面的右上角,单击个人资料照片,然后单击“设置”。

    用户栏中的 Settings 图标

  2. In the "Access" section of the sidebar, click Emails.

  3. 在“添加电子邮件地址”中,输入你的电子邮件地址并单击“添加”。 电子邮件添加按钮

  4. 验证你的电子邮件地址

  5. 在“Primary email address(主要电子邮件地址)”列表中,选择要与基于 web 的 Git 操作关联的电子邮件地址。 主要电子邮件地址选择

  6. 要在执行基于 web 的 Git 操作时对电子邮件地址保密,请单击“对我的电子邮件地址保密”。 对电子邮件地址保密的复选框图像

Setting your commit email address in Git

You can use the git config command to change the email address you associate with your Git commits. The new email address you set will be visible in any future commits you push to GitHub.com from the command line. Any commits you made prior to changing your commit email address are still associated with your previous email address.

Setting your email address for every repository on your computer

  1. 打开终端终端Git Bash
  2. 在 Git 中设置电子邮件地址。 可以使用 GitHub 提供的 noreply 电子邮件地址或任何电子邮件地址。
    $ git config --global user.email "YOUR_EMAIL"
  3. 确认在 Git 中正确设置了电子邮件地址:
    $ git config --global user.email
    email@example.com
  4. 将电子邮件地址添加到 GitHub 上的帐户,以便提交归属于你并显示在你的贡献图中。 有关详细信息,请参阅“将电子邮件地址添加到 GitHub 帐户”。

Setting your email address for a single repository

GitHub uses the email address set in your local Git configuration to associate commits pushed from the command line with your account on GitHub.com.

You can change the email address associated with commits you make in a single repository. This will override your global Git configuration settings in this one repository, but will not affect any other repositories.

  1. 打开终端终端Git Bash
  2. Change the current working directory to the local repository where you want to configure the email address that you associate with your Git commits.
  3. 在 Git 中设置电子邮件地址。 可以使用 GitHub 提供的 noreply 电子邮件地址或任何电子邮件地址。
    $ git config user.email "YOUR_EMAIL"
  4. 确认在 Git 中正确设置了电子邮件地址:
    $ git config user.email
    email@example.com
  5. 将电子邮件地址添加到 GitHub 上的帐户,以便提交归属于你并显示在你的贡献图中。 有关详细信息,请参阅“将电子邮件地址添加到 GitHub 帐户”。