Skip to main content

在 Git 中设置用户名

Platform navigation

可使用 git config 命令更改与 Git 提交关联的名称。 你设置的新名称将在从命令行推送到 的任何未来提交中显示。 如果您想要将真实姓名保密,则可以使用任意文本作为您的 Git 用户名。

使用 git config 更改与 Git 提交关联的名称仅影响未来的提交,而不会更改用于过去提交的名称。

  1. 打开终端终端Git Bash

  2. 设置 Git 用户名:

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

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

  1. 打开终端终端Git Bash

  2. 将当前工作目录更改为您想要在其中配置与 Git 提交关联的名称的本地仓库。

  3. 设置 Git 用户名:

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

    $ git config user.name
    > Mona Lisa