pm2-deploy: Git error «ambiguous argument...unknown revision or path not in the working tree» when deploying

Have used the same setup before with success, but this time it refuses to do a deploy properly.

The error log:

--> Deploying to preprod environment
--> on host 10.3.2.16
  ○ deploying origin/preproduction
  ○ executing pre-deploy-local
  ○ hook pre-deploy
  ○ fetching updates
Fetching origin
  ○ resetting HEAD to origin/preproduction
fatal: ambiguous argument 'origin/preproduction': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

  git reset failed

The config for preprod (which fails):

"preprod": {
            "user": "node",
            "host": "10.3.2.16",
            "ref": "origin/preproduction",
            "repo": "git@github.com:[something].git",
            "path": "/opt/www",
            "post-deploy": "npm install && pm2 reload pm2settings.json --env preprod"
        }

Note that I have the same config for the master and the production branch as well (to different servers), master works, preproduction and production fails with the message above.

Any tips?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 38 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I had the same problem, and I found the issue was because when pm2 sets up the git repository, it sets the git fetch config to be restricted only to the first branch that it was set up with. If you change this on subsequent deploys, it gives the git reset failed error above.

I found, on my local machine my .git/config had

[remote "origin"]
    url = git@github.com:repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

However on the pm2 deployed server in [deploy path]/current/.git/config, the fetch was restricted to the dev branch, which was the first branch it was setup with.

[remote "origin"]
    url = git@github.com:repo.git
    fetch = +refs/heads/dev:refs/remotes/origin/dev

SSH’ing into the server and changing the .git/config to a more permissive fetch = +refs/heads/*:refs/remotes/origin/* fixes the issue.

I’m not sure why it is set to such a restrictive config during setup - maybe security?

This has been fixed in #120 Waiting for a npm publish

same issue on 2.4.6

I still have the same issue with pm2 @ 2.4.2. What version should we try?

Should have been fixed @DQvsRA, try update your pm2 version

I have the same problem, so what is the status of this?