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

peterdickins's avatar

Git Error when deploying

I have a Laravel Vue SPA app. I am trying to deplying using forge.

I added the following lined to the deploy script to run npm

npm install
npm run build

However when I try to deply i get the following error:

error: Your local changes to the following files would be overwritten by merge:
    package-lock.json

Obviously I can discard the changes on the server, but what can I do moving forward to stop this happening every time I deploy?

0 likes
1 reply
gych's avatar

You could add these commands to your deploy script, change main to the branch where you're pulling from

git fetch origin main
git reset --hard origin/main

git fetch origin main Fetches changes from the remote main branch

git reset --hard origin/main Resets the branch to match the remote main branch

These commands will reset the branch on your server to match the remote branch. If you for example made a change to any of the branch files on the server these changes will all be lost. Its important that you understand what these commands do.

I personally use this myself to avoid conflicts and I never make any changes directly to the server branch files.

1 like

Please or to participate in this conversation.