Skip to content

Instantly share code, notes, and snippets.

@srgpsk
Created July 29, 2023 18:36
Show Gist options
  • Save srgpsk/f637814d46e2f8827e49f03144357eab to your computer and use it in GitHub Desktop.
Save srgpsk/f637814d46e2f8827e49f03144357eab to your computer and use it in GitHub Desktop.
Add empty directory to git

adding empty directories to your repository.

By default Git ignores empty directories, so you won't be able see them in git status or add with git add ....
To vercome the problem - add empty file in each dir that you want to keep in the repo.
Here's the oneliner:

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

It's doing next:

  1. Under curerent dir finds all the directories that are empty and don't belong to Git itself
  2. Creates an empty .gitkeep file in each of them

After that your git add command will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment