📜 ⬆️ ⬇️

The correct ways to exclude files in Git

Sometimes I .gitignore something in the .gitignore file that shouldn’t be there. For example, the .idea folder in which configs of known IDE from JetBrains lie. It is part of your work environment and is not related to the project and the repository. If several people work on a project and each of them adds configs of their environment to .gitignore, then it will turn into an unreadable trash bin.

In this topic, I will talk about the correct ways to exclude files and when to use which one.

Repository exception


When you have files that are specific to this project and for your working environment (for example, logs, third-party utility), use .git/info/exclude . This file is not committed and remains only in the local repository.

Exception for computer


When you have multiple projects and create something everywhere you don’t want to commit (for example, * .swp Vim files), use ~/.gitconfig . The above example folder .idea, which is created for each project is just right here. Create a .gitexcludes file and execute:
')
 git config --global core.excludesfile ~/.gitexcludes 

or manually add to ~/.gitconfig :
 [core] excludesfile = ~/.gitexcludes 

Immediately after saving ~/.gitconfig you should not see the specified files / folders in the list of Untracked files.

I love Git, but it is also sometimes inconsistent in the details. I draw your attention to the fact that in the first case we edit the .git/info/exclude file (without the s at the end), and in the second we use the excludeSfile option (c s in the middle). Do not lose time due to possible typos.

Working with Git in most cases means teamwork, so do not make life difficult for those who will work with you with the details of your work environment. Good commits! :)

Source: https://habr.com/ru/post/202696/


All Articles