What is .gitkeep?


Git is a development tool that helps teams manage their source code and handle projects efficiently. It's not possible to include blank/empty directories when uploading via GitHub or another hosting service. There's something wrong with that. Git provides a ".gitkeep" file that fixes this problem. It's good for pushing blank/empty folders with Git.

We will cover Gitkeep basics in this article as well as how to commit and push blank/empty Git directories

What is .Gitkeep?

It is kept by git to ensure blank/empty directories are never added remotely when pushing changes. Git will only find .gitkeep entries in bare folders. Once Git sees a blank/empty folder with a gitkeep file, it'll add it to subsequent commits or pushes.

It is true that using a .gitkeep file is a bit of a hack, but there is no doubt that it is an effective solution. This is only a workaround to the problem since there is no direct fix at hand. As long as this file is present in a folder, it's not blank/empty, is it? Because the blank/empty folder is not really blank/empty, we are going to include it anyway. Despite its logical contradictions, this has become a commonly used convention for Git.

How to Commit and push an Empty Directory or Folder With GitKeep

In order to commit and push changes to an blank/empty Git folder, you need to begin by creating it on your local machine. When you have finished the process, you will use the "cd" command to move, add, and move documents into the newly created folder. Once you have created a .gitkeep file, you will need to move it back into your main fol after creating the file. After the modifications have been committed, push them to the remote server after they have been committed.

Implement the steps that are outlined below.

Step 1  Grab the Repository you'd Like to Edit.

Using cd you can navigate to the location where you have your file on the local machine.

$ cd "C:\Users\muthu\Git-Keep\Example"

Step 2 − Make a directory in which your files will be stored.

It is possible for you to create a new directory on your computer by running a command called "mkdir" on your local machine.

$ mkdir example-dir

Step 3 − Ensure your changes are updated in the repository.

When you've finished making all the necessary changes, use the add command to permanently apply them

$ git add .

Step 4 − Locate the folder/directory

Next, go to the brand new folder/directory by executing the "cd new" command

$ cd new*

Step 5 − Create a gitkeep file

A ".gitkeep" file can be created by running "touch".

$ touch .gitkeep

Step 6 − Find the repository you worked on

Here's how you get back into the repository to make changes.

$ cd ..

Step 7 − Make changes and commit them

Your git repository can now be updated using git commit.

$ git commit -m "added successfully

Step 8 − Create an empty directory and push it

Here we will push the empty directory to the remote directory

$ git push origin

In this case, the "Everything updated" message is shown because the empty directory has already been pushed to the remote(origin)


These files are an essential part of most codebases that track empty files using Git. Dummy files don't always have to be named .gitkeep, but during your career as a developer, you will see the actual practice over and over again.

It is crucial to remember that there is a very slight distinction between files within the .gitignore file as well as those within the .gitfolders file, and this has to do with the fact that the .gitkeep file does not form part of the Git tool, its standard, or its API. The hidden menu is similar to In-N-Out Burger. There is no mention of a .gitkeep file in the official documentation, but regular users know it exists.

It is true that at the moment, it doesn't have anything that makes it stand out from the rest, but it will probably change in the near future. It is only a question of time whether or not it will receive official support in the near future.

Updated on: 04-Jan-2023

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started