Add .gitkeep to a bunch of folders

Published

August 12, 2022

I needed to add a bunch of folders to a GitHub repository. I knew their names but didn’t have any documents for them yet.

GitHub only allows you to push folders that contain something. However, you can use .gitkeep files to make “empty” folders.

First, I created all the folders that I needed.

letters <-
  c("a", "b", "c")

foldernames <-
  paste0("2022/", letters)
  
lapply(foldernames, dir.create, recursive = TRUE)

Next, I navigated to the new “2022” folder and created the .gitkeep files.

cd 2022

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