Software devlopment

gitignore


Ales Lerch
Ales Lerch
- 2 min read

Such a simple thing and yet it's quite complicated. I am talking about gitignore. It's very usefull when you are using git for your project.  Every project using git has special directory .git where is all git data stored. Now if we need some files to be ignored and not to be pushed to our repository we can use .gitignore fill with files and directories we wan't to ignore and it's done. But there is more how you can use this feature.

Global gitignore

Let's say you have rule like you need to apply all project to exists on you system. For that there is a global gitignore file. Let's say you are a Mac user. There is annoying meta file called .DS_Store. It's in every directory that you opened via gui ?. This definatelly should not be in any git repository .All you need is setup specific path and file and file this name there. Global gitignore is for unix systems:

~/.config/git/ignore
`

and for Windows:

%USERPROFILE%\git\ignore

Generate gitignore

Power of such file comes from complexity. However that means to make such a file, you have to write every rule - which can be tiredsome. Luckily there is a service that can be used to generate config file super easy and fast.

gitignore.io
Create useful .gitignore files for your project

Site gitignore.io is a open sourced tool where all you need is to visit the site, setup all needed parameters e.g.: what type of OS, IDE, language, etc. Site returns text page which can be used as a config. Simple as that.

What's even more cool is that you can generate whole config just via terminal. Here is an example:

curl -sL https://www.toptal.com/developers/gitignore/api/git,macos,vscode,python > .gitignore

Or you can install for your OS and shell. If you use macOS and fish as me all you need is to run this:

printf "function gi\n\tcurl -sL https://www.toptal.com/developers/gitignore/api/\$argv\nend\n" > \
"~/.config/fish/functions/gi.fish"

More info here: https://docs.gitignore.io/install/command-line.