How to add an empty directory in a remote git repository?

1

I have a PHP application that needs to upload photos to a remote directory, but this directory needs to be created previously in the repository in order to upload those files.

But when I send this empty directory, the repository does not recognize it.

How can I do to send an empty directory to the remote git repository?

    
asked by anonymous 10.05.2014 / 06:39

2 answers

4

Git does not allow having empty directories. But you can generate a hidden file inside the directory to upload this directory.

Most people do this by generating a file called .gitignore

In this way, if the data directory is empty, you can still upload the directory with the following command line:

touch data/.gitignore

Then by running the command git commit -a your remote repository will be updated with the hidden file within the desired directory.

    
10.05.2014 / 06:39
2

The .gitkeep file, which can be used in your project when, for several different reasons, you want to create an empty directory and commit it at a certain point in development. Ex: When you create a directory to save files like photos, PDFs and so on ...

The .gitkeep file is just a convention between developers, and there is no mention of it (so far) on official Git , but as it is a standard among developers, it is for you to "pass on a message" to others who will see your project in the future.

Create within your project the directory you want to commit and within this directory create a file called .gitkeep, leaving something like this ...

project-dir/
├── .git
├── other-dir
└── untracked-dir
    └── .gitkeep

Done, you can now run the commands git add [seus arquivos] and git commit -m [mensagem de commit] . Now when another developer comes across this file you will know what it's all about!

    
08.02.2018 / 12:14