Configure the global .gitignore file to solve the problem of multi-person development conflicts

Sometimes the projects we develop will inevitably use build packages such as npm. When git uploads the project, it is not necessary to upload these packages together. At this time, we can create a .gitignore file to ignore the submission of those files and ignore the submission. The configuration can also find commonly used templates on gitignore. And configuring a global .gitignore file can share an ignore commit configuration in any project, and it is not necessary to create a .gitignore in each project

Steps to create a global .gitignore file:

1. Use git bash to operate commands, open git bash in any file directory, and enter:

cd ~

Enter the computer user directory
2. Create a file .gitignore_global, the name can be modified by yourself, but there must be a "." symbol in front

$ touch .gitignore_global

3. Set the file as a global ignore configuration file

$ git config --global core.excludesfile ~/.gitignore_global

4. Open the file and add the required ignore configuration. gitignore .

node_modules/
unpackage/
dist/
.gitlab-ci.yml
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln

yarn.lock

5. Since .gitignore is only effective for files that have not been tracked (the newly added files later), and for the git project that already exists before, adding .gitignore later will not take effect. You need to

$ git rm -r --cached .

6. Cancel the tracking of all files

$ git add .
$ git commit - m '提交'
$ git push origin master

7. After submitting the project again, successfully ignore the submission of unnecessary files

Guess you like

Origin blog.csdn.net/weixin_44714325/article/details/108375819