Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git didn't push empty folders

Tags:

git

I init folder. Added all files commit them and than push them. Everything was looking fine...but i am missing some files and folder.

To example my .gitignore file

web/images/uploaded_profile_pictures/*

But there should be uploaded_profile_pictures folder... how to write it in .gitignore to ignore ONLY the content of the folder.. and keep the folder?

And second problem... why is there missing content???

After push

enter image description here

like image 955
Lukas Lukac Avatar asked Dec 20 '22 05:12

Lukas Lukac


2 Answers

There can't be folders without files in Git repositories, Git will always ignore empty folders (or folders that contain only ignored files). A common workaround is to create placeholder files in empty directories that you want to include in your Git repository.

touch web/images/uploaded_profile_pictures/.empty
git add web/images/uploaded_profile_pictures/.empty

Now for the .gitignore:

web/images/uploaded_profile_pictures/*
!web/images/uploaded_profile_pictures/.empty
# or just
!.empty

This will make Git ignore all files in that folder except of .empty, allowing you to add the folder to the repo.

For the second question: What kind of files are missing? Are those just random ones?

like image 175
JWhy Avatar answered Jan 05 '23 21:01

JWhy


As @Uroc327 mentioned in his comment, git doesn't handle "folders and files" but instead it uses "content".

This means that an empty folder is simply non existent to git.

This is a common problem, and the simplest solution is to add some "fake content" (an empty file) to a folder.

As @jwhy said, you could create a file named empty.
A more elegant approach (in my opinion) would be having in the folder web/images/uploaded_profile_pictures a file named .gitignore which contains the following:

*
!.gitignore
like image 25
Colin Hebert Avatar answered Jan 05 '23 21:01

Colin Hebert