1. Introduction
After the git tool is installed, you need to set some common configurations, such as email, abbreviation, git commit template, etc. This article will introduce in detail how to operate each configuration for reference.
2. Configuration steps
2.1 View the current git configuration
git config --global --list
Use the above command to view the global configuration in the current environment:
2.2 Configure username
User1 is used here for testing. During specific configuration, you can change the content in double quotes to your own user name.
git config --global user.name "user1"
You can see that the username has been modified successfully:
2.3 Configure email
During specific configuration, use your own email address to replace the content in double quotation marks. Here, "[email protected]" is used for testing.
git config --global user.email "[email protected]"
After entering the above command, you can see that the mailbox has been configured and taken effect:
2.4 Configuration command abbreviations
The purpose of configuring command abbreviations is to improve work efficiency. For example, to view the status of the current work, you need to enter "git status". After configuring "status" to the abbreviation "st", you only need to enter "git st" to view the status of the workspace.
//将status配置为缩写st
git config --global alias.st status
//将checkout配置为缩写co
git config --global alias.co checkout
//将commit配置为缩写ci
git config --global alias.ci commit
//将branch配置为缩写br
git config --global alias.br branch
After the configuration is completed, you can see that the effects of the commands "git status" and "git st" are the same. Other commands have the same effect and will not be described here.
2.5 Set notepad++ as the editor when setting git commit
Before configuring notepad++, you need to install notepad++ software first. The installation instructions are as follows: "Notepad++ download and installation steps [very detailed]"
git config --global core.editor \
"'D:/Mysoftware/notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Note: You need to find your local notepad++ installation directory, copy the path of notepad++.exe, replace the "\" in the path with "/", and then replace the content in the single quotes in the command.
After entering the command, you can see that when you enter the git ci command again, the notepad++ editor will automatically pop up:
2.6 Configure git submission template
Template content:
[Description]: Adjusting the file directory
[Project ]:
[Author ]:
[Type ]: feature/update/bug
[Modify ]: 1)
2)
3)
Copy the above content to a txt file, rename it to .git-commit-template, and place it in the same directory as .gitconfig:
The content of .git-commit-template is as follows:
After saving, enter the command to configure the template, and then modify and submit:
git config --global commit.template ~/.git-commit-complate
You can see that when you use git ci to submit again, the template we just configured appears in the submission information that pops up.
Then submit the modified information as needed:
After closing the interface, use the git log command to view the local submission information as follows:
The above indicates that the git submission template is configured successfully.
2.7 Configure git ignore files
During the code submission process, we do not expect to record the changes in some intermediate files generated such as .o files (if recorded, there will be too much change information when viewing the status, making it difficult to view the changes in the corresponding code). Then you can put intermediate file types such as .o into the .gitignore file.
Save the following information in a txt file and rename it to .gitignore, then submit it together with the project.
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
Follow the previous steps to submit it locally:
compile the main.c file at this time and generate a.exe. Check the status of the workspace again and find that it is still clean, indicating that git has ignored a.exe at this time.
At this point, the .gitignore file configuration is completed. You only need to submit it to the local and then push it to the remote. As long as there is a set .gitignore file in the subsequent project, the files that need to be ignored set in the file will be ignored by git.
Three, summary
This article records the relevant configuration after installing git for reference.