GIT Tutorials

HOME

Git is a Distributed Version Control System (VCS) which is originally developed in 2005 by Linus Torvalds (Creator of Linux) and is open source, i.e. freely available to use. It is the most popular and most used version control tool right now. A staggering number of software projects rely on Git for version control, including commercial projects as well as open source. 

Chapter 1 How to install Git on Windows 10
Chapter 2 How to create a new Git Repository – git init Command
Chapter 3 How to stage changes in Git – git add Command
Chapter 4 How to unstage the changes in Git – git rm command
Chapter 5 How to commit changes in GIT – git commit command
Chapter 6 How to track commits in Git – git log command
Chapter 7 How to commit an empty folder in GIT – gitkeep
Chapter 8 How to ignore files in GIT – gitignore
Chapter 9 How to create a branch in GIT
Chapter 10 How to stash changes in GIT – git stash command
Chapter 11 How to push new local GIT Repository to GitLab
Advertisement

How to commit an empty folder in GIT – gitkeep

HOME

In the previous tutorial, I have explained how to commit changes in GIT. This tutorial will explain how to commit an empty folder or directory in GIT.

GIT can not push empty directory or folder. It can only track files.

If we try to push a folder with nothing in it, although it will exist on our local machine, but nothing will go into the branch. A common, standardized practice to solve this issue is to push a file called .gitkeep into the empty folders. This is not a feature of GIT.

Let me explain this with an example

Step 1 – Create a GIT Repository with name GitTest.

Step 2 – Right-click and click on Git Bash Here to open GitBash at that place.

Step 3 – Create an empty directory named as login.

mkdir login

Step 4 – Type git status to check if new directory is tracked by Git or not. This image shows that GIT didn’t track the new directory login.

Step 5 – Create a new empty file called .gitkeep into the login directory.

touch login/.gitkeep

Step 6 – Type git status again and now the new directory login is tracked by GIT.

I hope this tutorial has helped you to understand this concept. Have a nice learning!!!