Skip to main content

gitkeep

Sometimes when working with Git you require empty folders to be part of your repository. Maybe because you want to underline the importance of certain directories for storing certain files in the future. Maybe some part of the logic depends on those directories being there.

However, because Git only versions files, it is unable to add empty directories .

One well known hack to get around this problem is to version dummy files inside the empty directories you wish to add to your repository, in order to force the directory into source control.

Gitkeep is a tiny command line utility written in Python that makes it easy to use this hack, by creating .gitkeep files in the directories of your choosing.

In the Bash command line it is the equivalent of running:

find . -type d -empty -exec touch {}/.gitkeep \;

However, using the Bash command above forces you to do the same for each directory path you wish to version, and then to manually delete any exceptions.

Also, Windows users do not have the luxury of the Bash command line unless they install Cygwin.

Install

If you already have Python installed, simply run:

pip3 install gitkeep2

Use

To create a .gitkeep file in a specific directory called 'foo':

gitkeep path/to/foo

To add a message to your .gitkeep file in order to let fellow developers understand why it's important to keep the specified directory in source control you can use the --message or -m flag:

gitkeep path/to/foo -m "This is where we'll later add X stuff."

By default all .gitkeep files bear the date of creation, the URL to this project and a default message. The idea here is to help others maintaining your project in the future understand what these files are. However, if you'd prefer to create empty .gitkeep files you can do so with the --empty or -e flag:

gitkeep path/to/foo -e

To remove a .gitkeep file from a specified path use the --let-go or -l flag:

gitkeep --let-go path/to/foo

To create .gitkeep files recursively in a path and all its sub-directories use the --recursive or -r flag:

gitkeep --recursive path/to/foo

To remove all .gitkeep files recursively from a path and all its sub-directories use a combination of the -r and -l flags above:

gitkeep -lr path/to/foo

Implementation Notes

Gitkeep is powered by Click.

Develop

First prepare a virtual environment to install your local copy. From the root of your project run:

virtualenv venv
New python executable in venv/bin/python
Installing setuptools, pip............done.

Activate the corresponding environment. On OS X and Linux, do the following:

. venv/bin/activate

Notice the prompt of your shell has changed to show the active environment.

Get Click installed in your virtual environment:

pip3 install Click

To install gitkeep in your virtual environment:

pip3 install --editable .

Then just try running gitkeep:

gitkeep --help

To go back to the real world, run:

deactivate

Release files for gitkeep2 1.0.0.post1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gitkeep2 1.0.0.post1
File Size Uploaded
gitkeep2-1.0.0.post1.tar.gz 4.3 kB Details

Release files / gitkeep2-1.0.0.post1.tar.gz

Download URL gitkeep2-1.0.0.post1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3b1f644972fd89508b090f647534e44d682832d859eef05d431adc314bcadf28
BLAKE2b-256 checksum
How to use checksums
fe1e9cc728d2d8236eb6418e58da42cbcea04d66b5c14ef1085d4f7f0ec2b834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

1.0.0.post1 This release

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page