Storage link is not included when doing a Git push Laravel
Asked Answered
H

2

5

I just have done a git push in our online repo

When I checked the online repo and checked the public folder it shows this: enter image description here

while in my local repo I have this in my public folder:

enter image description here

My local has Storage folder from my storage link. I am guessing that this has something to do with the .gitignore inside my local public folder. It contains:

*
!.gitignore

Same goes with my storage folders. In our Online repo inside storage/app/public: enter image description here

while in my local storage folder:

enter image description here

user_images is present in my local repo. Here is the inner .gitignore:

*
!.gitignore

and the outer .gitigore:

*
!public/
!.gitignore

I am not quite familiar with setting rules in .gitignore. I wish to make sure that whatever my local Storage and public folder has, the Online repo has as well. How should I go about in doing this?

Kindly edit my tags if it is misleading or incorrect. Thank you.

This is the content of the root .gitignore:

/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log

I have removed /public/storage in .gitignored and tried to do a git push

Changes not staged for commit:
        modified:   .gitignore

and still, nothing is the same from my local to Online repo? Anything I might have missed?

Tried running git check-ignore -v path/to/file

In my root .gitignore:

/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log

If I ran git check-ignore -v public/hot, it replies with .gitignore:2:/public/hot public/hot but if I ran git check-ignore -v public/storage, it doesn't respond with anything which it should because it is included in root .gitignore I come to believe that this situation made it impossible for the public/storage/user_images and storage/app/public/user_images. Any help is needed.

I may have been viewing a wrong file or path all this time. But I can confirm that @VonC method helped me do a proper exclusion in gitignore. Thanks.

EDIT:

Final gitignores so far

root .gitignore:

/node_modules
# /public/hot
# /public/storage
/storage/*.key
/vendor
.env
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log

storage\app.gitignore

# *
# !public/
!.gitignore

storage\app\public.gitignore

# *
!.gitignore

public\storage.gitignore

# *
!.gitignore

Just an additional info:

git check-ignore -v vendor gives .gitignore:5:/vendor vendor

while git check-ignore -v /vendor gives fatal: C:/Program Files/Git/vendor: 'C:/Program Files/Git/vendor' is outside repository

I'm not sure where git check-ignore -v path points to.

Hoyle answered 6/2, 2019 at 3:8 Comment(19)
The storage folder inside your local screenshot has user uploaded images. I do not think that will be a a good data to push into repo, why is it needed?Helsa
because in my project, if the user doesn't upload an image, that noimage.jpg will be used as default. What are your suggestions?Hoyle
Is there a way we can include noimage.jpg as an exemption? or if not at least everything else in my local reflects exactly to the online repo?Hoyle
What is the content of ,gitignore inside the laravel root?Helsa
I have included the contents of root .gitignore in my post. I hope it helps.Hoyle
you have /public/storage in .gitignore and hence the storage folder is ignored in the push :)Helsa
Oh I see, so it goes without saying that I should also remove /storage/*.key to reflect all my local folders in storage to online storage folder? Or the /public/storage is enough to solve both public and storage folder synching?Hoyle
I would say move the image outside storage folder and put it inside public/img folderHelsa
wait why? That would cause all my img src path to mess up? Is there a way to exclude storage folder altogether?Hoyle
If you really want then you can just remove the public/storage entry from gitignore and push the changes. It will automatically show you to add the storage folder it will show in red as untracked.Helsa
I will try that as recommended, I'll also see if it includes the noimage.jpgHoyle
Updated result in the postHoyle
Now if you do git status, can you see public/storage in red ?Helsa
Yes it says: Changes not staged for commit: modified: .gitignoreHoyle
do git add .gitignore public/storage and git pushHelsa
after doing git push it said Everything up-to-date and when i did a git status it says Changes to be committed: modified: .gitignore in green color.Hoyle
ohh did you do git commit after add and before push?Helsa
Do not keep resources in storage. Add a new folder under assets which you copy on build to the public folder.Cardiovascular
@MihirBhende I did a git add .gitignore public/storage, git commit -m "test", git push and checked online repo but it still has no public\storage\user_images and storage\app\public\user_images where am I doing it wrong?Hoyle
C
6

First, for any file ignore within a folder, type:

git check-ignore -v -- path/to/file

That will display exactly which .gitignore is responsible for ignoring said file.

Second, the rule of gitignore is simple:

It is not possible to re-include a file if a parent directory of that file is excluded.

To exclude files (or all files) from a subfolder of an ignored folder f, you would do:

f/**
!f/**/
!f/a/sub/folder/someFile.txt

Meaning: you need to whitelist folders first, before being able to exclude from gitignore files.

Cannonry answered 6/2, 2019 at 5:48 Comment(10)
I did git check-ignore -v storage/app/user_images and it responded storage/app/.gitignore:1:* storage/app/user_image so what i did is commented the # * so upon doing a check-ignore again nothing showed. proceeded in doing a: git add *, git commit -m "test", git push but still the online repo has no storage/app/user_images directory. Am I doing anything wrong here?Hoyle
@JustinF As long as nothing shows, keep doing git check-ignore -v: you will see what rule block. Then re-read the rule I mention: any folder content ifnored is generally ignored because a parent folder was already ignored itself.Cannonry
something weird is happening. I edited root .gitignore in my project, I have these two lines: /public/hot, /public/storage when I check-ignore public/hot is replies .gitignore:2:/public/hot public/hot but if I check-ignore public/storage it does not reply anything even though it is clearly included in the .gitignore file. Is there anything unusual happening here?Hoyle
@JustinF Check-ignore a file: Git does not version folders. As a best practice, when ignoring folders (content), always put a trailing '/' in your .gitignore rules (for folders): /public/storage/ or /public/hot/Cannonry
@JustinF Also, what were the final gitignore rules you have set up?Cannonry
@JustinF I confirm the check-ignore only takes relative paths from the root of the git repo, not absolute paths.Cannonry
Can you explain further what it was meant by relative paths from the root? I didn't quite get it.Hoyle
@JustinF in your case, if you cd to the root folder of your repo, the git check-ignore command would use public/storage (relative to that current folder), not /public/storage.Cannonry
basically git check-ignore means project-name/ and not just project-name (without slash)? is this correct?Hoyle
@JustinF means afile, or afolder/, in that (for the folder case) git check-ignore will test if files within that folder are ignored by a .gitignore rule. But in both cases, the path to a file (or the path to a folder) passed as an argument would be relative to your current folder, inside the repo.Cannonry
G
2

For those who might still be searching for an answer, edit the .gitignore files in storage/app and storage/app/public folders and remove the first 2 lines from each.

Genera answered 5/5, 2020 at 5:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.