How to fix git pull failed on a deploy via PM2

If you get the error message git pull failed on a deploy via PM2 maybe it's because you are generating some files on the fly that you don't need to save, keep reading to learn more about how to fix it!

⚠️ Error message and cause

This is the output:

Please, commit your changes or stash them before you can merge.
Aborting

  git pull failed

Deploy failed

If you are not sure about what changes you can find the changed files running git status

In my case, the cause was due some files generated by Grunt on each deploy that I don't need in the next deploy so I can remove them.

How to fix it ✨

In your PM2 deploy file, typically the deploy.json add a pre-deploy command inside your environment block

deploy: {
    production: {
      ...
      'pre-deploy': 'git reset --hard',
      ...
    }
  }

This will delete the changes on the servers and then will fetch the repo and deploy without problem 🙂

Need more info? Read documentation about deployment with PM2

Leave a comment with your experience or questions ✍️
👋 Thanks for reading!