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

fredemagi's avatar

Issues with Github when deploying with Laravel Forge

When I make some local changes to let say a js file, I would run npm run dev on my local machine to recompile all js files into a single app.js, which is located in public. When I then push to git, Laravel Forge shows the error from git in the deployment process that some files would be overwritten by a merge (I guess it’s the old app.js on the server which is to be replaced by a new). When Laravel Forge deploys, it runs this: https://gist.github.com/BenSampo/aa5f72584df79f679a7e603ace517c14. This includes npm run prod. Should the app.js file on both my local machine and the server be added to the gitignore, or should the script somehow delete the old app.js before pulling from github?

0 likes
4 replies
ejdelmonico's avatar

Yes, you need to gitignore public/js, public/css and public/storage if using it. Then, remove those files from your git repo by committting, git rm -r --cached and push.

ejdelmonico's avatar

Perform the .gitignore edit locally and run git rm -r --cached to remove the old files that are now ignored. Commit the changes. Then, push to the remote repo. Forge should replace the files when it pulls the new version as long as you have Quick Deploy turned on. If not turned on, then just press the Deploy Now button in Forge.

Please or to participate in this conversation.