How to Add an Empty Folder in Git?
There is no git official tool to push an empty folder or directory to Git repository. However, the Git user community uses a convention for adding an empty file in a Git repository.
In Git, the empty folders are not tracked, so if you want to add an empty folder to an reposity then you need to include at least one file into the folder.
Sometime you may want to include an empty directory in your repository, perhaps you plan to add file in it in future or because it can be used as a placeholder for some purpose.
Use .gitkeep or .placeholder to Commit and Push an Empty Git Folder or Directory
So, here is a trick…
Create a file name
.gitkeep inside an empty folder/directory, this file can contain comments or any text, typically this file is empty.
The file name can be
.gitkeep, the name is just a convension, but
.gitkeep is commonly used because its self-descriptive and unlikely to conflict with other file names.
The following are the commands to push an Empty Folder
Step #1: Create an Empty folder using
Step #2: Move into the empty directory with the
Step #3: Create a hidden file
touch .gitkeep command.
Step #4: Use
git add . to update the Git index.
Step #5: Use
git commit -m "<add statement>" to commit the code locally.
Step #6: Use
git push origin to push the code.
The following are the commands to push an Empty Folder.
mkdir empty-folder cd empty-folder touch .gitkeep git add . git commit -m "Adding empty foler named empty-folder" git push origin