Use git config --global to set username and email, as well as global and local configuration of git config

1. Introduction to the article


Why do we need to set up username and email?

When we register githuband gitlabwait, we generally use username or email address:

Insert image description here

This username can be your name, your mobile phone number, or a string of other letters.

When your registration is complete, it will be written to .gitthe account. Every time you submit code, your account will be displayed.

Since I used a mobile phone number to register, other colleagues would come over and ask me when they saw the mobile phone number: Is it the code I submitted?

This caused trouble for other colleagues.

Therefore, in order not to cause trouble to other colleagues, I need to modify my account (mobile phone number) and set it to my name.

You can use any letters or numbers to register github, gitlabbut during the actual development process, you need to modify your account to let your colleagues know that this is the code you submitted, so that you can happily develop code together.

Account configuration is divided into 全局配置and 本地配置, next, I will analyze them in detail.

2. Global configuration


Before we configure it, we can use the following code to view your current username and email:

# 查看全局配置用户名
git config --global user.name

#查看全局配置的邮件
git config --global user.email

There are two ways to set global settings:

  1. Command mode

  2. Configuration file mode

Choose either of the two methods to configure the account and email address for global gitproject submission gitinformation.

2.1 Command mode


In gitthe server, any non-local git repo, use the following command to configure the global:

# 修改全局配置用户名
git config --global user.name "你的用户名"

# 修改全局配置邮件
git config --global user.email "你的邮件地址,比如[email protected]"

2.2 Configuration file method


Edit 〜/.gitconfig, its content .git/configis the same as that in the file, that is, [user]add some information to 〜/.gitconfigthe file, the content is as follows:

[user]
    name = your-username
    email = your-email-address

Save and exit, use the following command to check whether the configuration is successful:

git config --global -l

Or use the following command:

# 查看全局配置用户名
git config --global user.name

#查看全局配置的邮件
git config --global user.email

3. Partial configuration


Global configuration is to configure gitall current projects, but sometimes we only configure a certain project, which can be configured in the following way.

There are also two ways to set local settings:

  1. Command mode

  2. Configuration file mode

Choose either of the two methods to configure the account and email address gitfor submitting gitinformation for the current project.

3.1 Command mode

  1. Go into one of your projects, then right-click the mouse and select Git Bash Here , as shown below:

Insert image description here

  1. Then, enter the following command to modify the project account:

# 修改配置用户名
git config user.name "你的用户名"

# 修改配置邮件
git config user.email "你的邮件地址,比如[email protected]"
  1. Use the following command to check whether the modification is successful:
# 查看配置用户名
git config user.name

#查看配置的邮件
git config user.email

3.2 Configuration file method


For local git repoconfiguration, first enter the local gitproject folder, edit .git/configthe file, and add the following information:

[user]
    name = 你的用户名
    email =你的邮件地址,比如[email protected]

Insert image description here

Save and exit.

命令方式In the above 配置文件方式two methods, you can git repouse the following command in the local folder to check whether the account and email address of the local project have been changed successfully.

git config -l

或者

# 查看配置用户名
git config user.name

#查看配置的邮件
git config user.email

For many locales , a customized local account and email address must be set up git repofor each locality .git repogit

Sometimes we don't want to set each one, we can use the above gitglobal configuration, all locals git repouse the global configuration!

4. Summary


Through the analysis of this article, you should know:

  1. Why do I need to set up a username and email?

  2. How to set up username and email

    • How to set up locally

    • How to set up globally

Guess you like

Origin blog.csdn.net/lvoelife/article/details/133267758
Recommended