Skip to content

Instantly share code, notes, and snippets.

@jlollis
Last active November 11, 2024 10:37
Show Gist options
  • Save jlollis/54d3b3a7ed12776ac9f0d4bc13e63ed9 to your computer and use it in GitHub Desktop.
Save jlollis/54d3b3a7ed12776ac9f0d4bc13e63ed9 to your computer and use it in GitHub Desktop.
.gitkeep - Push your entire folder structure to GitHub, including empty folders

.gitkeep

A .gitkeep file tells github to do the opposite of its default behaviour, which is to ignore empty folders.

If you want to track an empty folder, or a folder with untracked files, create a 0kb file with the .gitkeep file extension in that folder.

touch FOLDER_NAME/.gitkeep

To push your project's folder structure to Github:

To create a .gitkeep file in each of your folder subdirectories, run this bash script from the root of your source project:

find . -type d -empty -not -path "./.git/*" -exec touch {}/.gitkeep \;

Here is the PowerShell equivalent:

Get-ChildItem -Recurse -Directory | ForEach-Object {New-Item -ItemType file -Path "$($_.FullName)" -Name ".gitkeep" }

To check-in a directory but not the files:

If you want to ignore everything inside the directory, but at the same time want to check-in the folder, add the following lines in your .gitignore:

# ignore files in folder
FOLDER_NAME/*

# ...but keep the folder
!FOLDER_NAME/.gitkeep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment