Eli Chitrit
Eli Chitrit

Reputation: 17

How can I ignore public folder on git push?

I have a Node.js project hosted on Heroku and I am trying to ignore my public/ folder from push when I upload to Heroku. I included the line public/ in the .gitignore file which this is the folder I don't want to override but it's not working. When I push to Heroku all of the images stored in the public/ folder on the server are deleted.

Here is my .gitignore:

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
# Dependency directories
node_modules/
public/

Why is this happening, and how can I prevent it?

Upvotes: 0

Views: 2552

Answers (2)

Chris
Chris

Reputation: 136918

When I push to Heroku all images from server are deleted

I suspect these are images that have been uploaded by users? This directory should be ignored and untracked, but that won't be enough on Heroku due to its ephemeral filesystem. Any changes you make will be lost whenever your dyno restarts. This happens frequently (at least once per day).

Heroku recommends storing user uploads on a third-party service like Amazon S3.

Upvotes: 1

onuriltan
onuriltan

Reputation: 3898

You might deleted the folder from your git repository as well. Did you use a git command like this git rm -r --cached your_folder/

If you don't want to track a folder anymore and keeping it in your git repository first you need to add the folder to the .gitignore file like you did, and then you need to use

git update-index --assume-unchanged public/*

If you want to track the folder again you can use

git update-index --no-assume-unchanged public/*

See more at this guide which is more detailed.

Upvotes: 0

Related Questions