Git is one of the most used version control system(vsc). A version control system records changes to a file or set of files over time so that you can recall specific versions later. For more information see.
I assume that you’ve already base knowledge about Git. I am gonna concentrate on
.gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git will not be affected. As we notice from the official description, the file or folder that should not be pushed to the repository has to be in
.gitignore file. Actually, this is a kind of Blacklist which is the most known way of writing
.gitignore file. There is also another way of writing
.gitignore file → Whitelist.
What is a
.gitignore as whitelist? Probably you’ve already guessed it is opposite of blacklist that’s mean, you will add explicitly exclamation mark (!) then a file name, extension or folder name that has to be in your repository.
The main intention to use the whitelist as a developer you have to always explicitly add file in .gitignore which has to be pushed. Developers especially the beginning of their carriers faced kind of issues such as pushing undesirable files to the repository. Via whitelist you don’t have to worry after hitting git add command. This is one of the best practices of git usage. Let’s see the example below to make clear.
My project structure looks as below:
$ tree my_project/
│ ├── main.cpp
│ └── play.cpp
│ ├── playTest.cpp
│ └── testAll.cpp
│ ├── deployment.conf
│ └── analyse.conf
In this case, let’s say you want to push all files except profile.html file. Then the
.gitignore file as white list it should be written as:
The syntax may confuse at the beginning but is actually quite straightforward. The exclamation mark (!) tells git do not ignore those files. The rest of the files will be ignored. In our example, profile.html file will be ignored.
Now you know how to write a
.gitignoreas a whitelist. No more undesirable files or folders in your repository. Happy coding!
For any critic or question, please write me on twitter.
* https://git-scm.com/docs/gitignore* https://kapitel26.github.io/git/2014/03/06/gitignore-positivliste.rb.html