Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrisgrim's avatar

Issue with gitignore when pushing laravel site to server

Hi, I recently setup post-receive hooks on my digital ocean droplet and connected it with my laravel local project. Everything works great except my public/storage/images don't get uploaded with each commit. I tried to edit my local .gitignore file so it doesnt include the public/storage folder but nothing is being uploaded when I commit. Here is my current .gitignore file contents

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

I changed the /public/storage and /storage/*.key

Thanks Chris

0 likes
8 replies
Minahgo's avatar

For clarification... by not uploaded you mean that you can see the files in your commit but when you push to production some files aren’t moved? Or are the files not showing up in the commit at all?

If it’s the later then you probably need to add them to the commit manually since they were on the ignore list before.

Otherwise check the folder in your server and see if the files are there but just not linked since the storage folder did require a symlink at some point if I remember correctly.

Let me know how that goes!

chrisgrim's avatar

Hi @sepiksu

When I first created the git init and then connected it to my server it already put an ignore in my images. So I removed the /public/storage from the .gitignore file and edited one of the images. Then I recommitted and saw that the new file had been committed. Then I tried to push it to my server but the image wasn't uploaded.

mac03733's avatar

are u trying to upload the image manually by just putting it in a folder then pushing??

or

are u uploading through ur project??

on your server ..try running the following command

php artisan storage:link

then try upload

Minahgo's avatar

Okay! Now we are getting closer to the problem. How did the item end up in the /public/storage folder in the first place? Did you manually put it in there or did you upload it via a form in your application, like a profile picture for example?

I am asking because the /public/storage folder is not really a folder but a so called symlink, at least that's what it should be. It works kind of like a desktop shortcut on windows. That is also the reason why it is part of the .gitignore file and shouldn't be committed. The files themselves are usually stored inside /storage/app/public. Check in there for me please and see if they are in there.

Since git is not know to just bypass files that are part of the commit it is very likely that you forgot to link the storage folder on your server. You can do that by going to your servers command line, inside your project folder and type:

php artisan storage:link

After this file uploads should work since the link from /storage/app/public to /public/storage will be created.

Let me know if that solves the problem or if anything is unclear.

Palak27's avatar

@chrisgrim

put .gitignore file in folder you want to upload to serve

and put this content is .gitignore file

*
*/
!.gitignore
chrisgrim's avatar

Hmm ok now this is getting interesting. When I ran php artisan storage:link I get the error

   ErrorException  : symlink(): No such file or directory

I looked this up and its because I moved a laravel directory. So I removed the public folder from the storage and then reran the storage:link. It worked this time and created the sym link.

However when I ran the git push to my server and then tried running the storage:link I get the same error again.

Minahgo's avatar
Minahgo
Best Answer
Level 8

@CHRISGRIM - That happened because you overwrote your changes on the server with your newest push. You can tell that by the fact that you received your old error message instead of this one:

The "public/storage" directory already exists

The only way to do this is to reverse the changes locally as well and then commit them. You want to put /public/storage back into the .gitignore before you commit and remove the folder from your future commit by typing this in your local command line:

git rm -r --cached /public/storage

Once you are done with that you should be able to commit and push as usual and the server changes should no longer be overwritten.

Please or to participate in this conversation.