Skip to main content

此版本的 GitHub Enterprise Server 将于以下日期停止服务 2025-03-05. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

Setting your username in Git

Git uses a username to associate commits with an identity. The Git username is not the same as your GitHub username.

Platform navigation

About Git usernames

You can change the name that is associated with your Git commits using the git config command. The new name you set will be visible in any future commits you push to GitHub from the command line. If you'd like to keep your real name private, you can use any text as your Git username.

Changing the name associated with your Git commits using git config will only affect future commits and will not change the name used for past commits.

Setting your Git username for every repository on your computer

  1. 打开终端终端Git Bash

  2. 设置 Git 用户名:

    git config --global user.name "Mona Lisa"
    
  3. 确认您正确设置了 Git 用户名:

    $ git config --global user.name
    > Mona Lisa
    

Setting your Git username for a single repository

  1. 打开终端终端Git Bash

  2. Change the current working directory to the local repository where you want to configure the name that is associated with your Git commits.

  3. 设置 Git 用户名:

    git config user.name "Mona Lisa"
    
  4. 确认您正确设置了 Git 用户名:

    $ git config user.name
    > Mona Lisa
    

Further reading