What is .gitkeep? Differences between .gitignore and .gitkeep

what is gitkeep vs gitignore

Did you ever encounter .gitkeep in any git project? You might. If you install recent angular 2 or angular 4 projects via angular CLI, you will see one .gitkeep file in the ./src/app/assets folder. So you might wonder what is this file? We all know about our friend .gitignore. You may feel it is a sibling of .gitignore. Is there any kind of special attention given by Git to this magical file?

What is .gitkeep?

Before knowing this, we must know that Git does not track empty directories. If you have an empty directory, git will never see this. It is an intended feature. Now if you put one file to this directory, git will start tracking this directory. This file may be anything and this file may contain anything and the name of the file may be anything.

So where is .gitkeep? Actually, the community decides to name this magical file to be .gitkeep. So others can easily relate. Git software does not give any special attention as it does to .gitignore.

Now if you wish to track or push an empty directory to your upstream, just create one .gitkeep file and enjoy. Other developers would easily understand. Generally, people do it with their assets folder or log folders. It is important to check that you never add “.gitkeep” into the .gitignore. Then the whole purpose of the tracking the empty directories would vanish.

A few part of the community started to add .gitignore files to the empty directories but the larger part of the people find it bit confusing. Gitignore file is used by Git to ignore the files from your version control system. So I too find it little of the track to add one .gitignore file to your empty directories to track them.

PS: It is the 12th year birthday of our beloved Git. So happy open-sourcing.

Leave a Reply

Your email address will not be published. Required fields are marked *