乐闻世界logo
搜索文章和话题

How to change my Git username in terminal?

1个答案

1
  1. Global Username Configuration: If you wish to change the global username, which applies to all your Git repositories, use the following command:
bash
git config --global user.name "new username"

Here, replace ""new username"" with your desired username.

  1. Repository-Specific Username Configuration: If you only want to change the username for the current repository, use the following command:
bash
git config user.name "new username"

This command only affects the configuration for the current repository.

Example

Suppose your original username is oldname, and you want to change it globally to newname. Enter the following command in the terminal:

bash
git config --global user.name "newname"

To verify whether the username has been set successfully, use the following command to check the current global username configuration:

bash
git config --global user.name

This will display newname, confirming the username has been updated successfully.

Additionally, if you want to use a different username projectname for a specific project, run the command in the root directory of that project:

bash
git config user.name "projectname"

Then, use:

bash
git config user.name

to confirm the username has been changed to projectname in that project.

2024年6月29日 12:07 回复

你的答案