Article directory
1. Introduction to the article
Why do we need to set up username and email?
When we register github
and gitlab
wait, we generally use username or email address:
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 .git
the 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
, gitlab
but 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:
-
Command mode
-
Configuration file mode
Choose either of the two methods to configure the account and email address for global git
project submission git
information.
2.1 Command mode
In git
the 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/config
is the same as that in the file, that is, [user]
add some information to 〜/.gitconfig
the 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 git
all 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:
-
Command mode
-
Configuration file mode
Choose either of the two methods to configure the account and email address git
for submitting git
information for the current project.
3.1 Command mode
- Go into one of your projects, then right-click the mouse and select
Git Bash Here
, as shown below:
- Then, enter the following command to modify the project account:
# 修改配置用户名
git config user.name "你的用户名"
# 修改配置邮件
git config user.email "你的邮件地址,比如[email protected]"
- 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 repo
configuration, first enter the local git
project folder, edit .git/config
the file, and add the following information:
[user]
name = 你的用户名
email =你的邮件地址,比如[email protected]
Save and exit.
命令方式
In the above 配置文件方式
two methods, you can git repo
use 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 repo
for each locality .git repo
git
Sometimes we don't want to set each one, we can use the above git
global configuration, all locals git repo
use the global configuration!
4. Summary
Through the analysis of this article, you should know:
-
Why do I need to set up a username and email?
-
How to set up username and email
-
How to set up locally
-
How to set up globally
-