Pm2: Is there a reason why `pm deploy` needs to be run in a git repo?

Created on 23 Dec 2015  ยท  15Comments  ยท  Source: Unitech/pm2

danny@admins-iMac ~> pm2 deploy /Users/danny/git/test-deploy/test.json staging
--> Deploying to staging environment
--> on host test.cloudapp.net -p 22
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>

  commit or stash your changes before deploying

Deploy failed
danny@admins-iMac ~> mkdir test
danny@admins-iMac ~> cd test
danny@admins-iMac ~/test> git init
Initialized empty Git repository in /Users/danny/test/.git/
danny@admins-iMac ~/test> pm2 deploy /Users/danny/git/test-deploy/test.json staging
--> Deploying to staging environment
--> on host test.cloudapp.net -p 22
fatal: no such branch: 'master'
  โ—‹ deploying origin/master
  โ—‹ executing pre-deploy-local
  โ—‹ hook pre-deploy
  โ—‹ fetching updates
Fetching origin
  โ—‹ resetting HEAD to origin/master
...

Most helpful comment

I am having the exact same error.
pm2 deploy setup works fine but the deploy itself doesn't

It clones and the target directory is configured, and it clones without issue.
then when running the actual pm2 deploy I get the same message

pm2deploy@basenode-1:/var/www$ pm2 deploy ~/ecosystem.config.js dev setup
--> Deploying to dev environment
--> on host localhost
  โ—‹ hook pre-setup
  โ—‹ running setup
  โ—‹ cloning [email protected]:zyzyzyzyzy/nodeapps.git
Cloning into '/var/www/source'...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 7 (delta 0), reused 4 (delta 0), pack-reused 0
Receiving objects: 100% (7/7), done.
Checking connectivity... done.
  โ—‹ hook post-setup
  โ—‹ setup complete
--> Success
pm2deploy@basenode-1:/var/www$ pm2 deploy ~/ecosystem.config.js dev
--> Deploying to dev environment
--> on host localhost
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>

  commit or stash your changes before deploying

Deploy failed

All 15 comments

pm2-deploy only git versioned projects. The git repo + branch need to exists on the remote server

@Unitech the repo in the json file does exist. The problem is that the pm2 wants wo be run in a git repo locally when deploying something remotely. It does not even have to be the one being deployed to the server as can be seen in the posted snippet. This is weird if one tries to set up some CD.

The first command fails, because pwd is the home directory, which is no git repo. The second try succeeds because pwd is an empty, just created git repo, which has nothing to do with the project being deployed.

I hope this explains the problem in a better way. If not I'm willing to elaborate more.

I've been wondering what I've been doing wrong and it turns out I'm having exactly the same issue ("Not a git repository"). I've now put my deploy scripts in a folder and ran git init. The command now works fine! This seems to still be an outstanding issue.

@Unitech would you consider reopening this issue or explain what the git repository is needed for? I think it's just running a couple of checks, but not all of them seem to be necessary for running pm2-deploy.

@jstans guess you've missed pm2 deploy <configuration_file> <environment> setup, or you have a passphrase to your rsa key

@egorlitvinchuk so ...setup invokes git init?

@despairblue In your remote repo, yes.

@vmarchaud OK, then this won't fix the problem. The problem is that the working directory of your local shell needs to be a git repo. As can be seen in the example in the first post this can be fixed by making a git repo in your current working directory.

My configuration file is in a repo. I'm just invoking pm2 from another directory.

I'm also not using pm2 any more. So maybe this was fixed. I just assumed it isn't, because of @jstans comment.

@egorlitvinchuk I've just done another test, setup is running fine. The subsequent run does not. No passphrase on key. I used to get around this by running the subsequent command relative to the directory it's been installed under; which seemed to eliminate the point of the deploying somewhat. So I was glad to see it worked when a git init was run.

jstans@pc:~/test$ sudo -u node pm2 deploy test.json production setup
--> Deploying to production environment
--> on host 127.0.0.1
  โ—‹ hook pre-setup
  โ—‹ running setup
  โ—‹ cloning [email protected]:jstans/test.git
Cloning into '/srv/node/test/source'...
  โ—‹ hook post-setup
  โ—‹ setup complete
--> Success
jstans@pc:~/test$ sudo -u node pm2 deploy test.json production
--> Deploying to production environment
--> on host 127.0.0.1
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>

  commit or stash your changes before deploying

Deploy failed

@jstans looks like that you've modified something on remote host. So I advise you to wipe /srv/node/test/source folder, try again setup and then simple deploy.
That worked for me recently, when I was stucked on the same situation :)

@egorlitvinchuk I have tried that. It's the same thing everytime I try until I make the working directory a git repository first by running git init.

I am having the exact same error.
pm2 deploy setup works fine but the deploy itself doesn't

It clones and the target directory is configured, and it clones without issue.
then when running the actual pm2 deploy I get the same message

pm2deploy@basenode-1:/var/www$ pm2 deploy ~/ecosystem.config.js dev setup
--> Deploying to dev environment
--> on host localhost
  โ—‹ hook pre-setup
  โ—‹ running setup
  โ—‹ cloning [email protected]:zyzyzyzyzy/nodeapps.git
Cloning into '/var/www/source'...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 7 (delta 0), reused 4 (delta 0), pack-reused 0
Receiving objects: 100% (7/7), done.
Checking connectivity... done.
  โ—‹ hook post-setup
  โ—‹ setup complete
--> Success
pm2deploy@basenode-1:/var/www$ pm2 deploy ~/ecosystem.config.js dev
--> Deploying to dev environment
--> on host localhost
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>

  commit or stash your changes before deploying

Deploy failed

@ghost how did you solve it? I have the same problem...

same problem here, sounds is not passing the pwd to the command git context

Was this page helpful?
0 / 5 - 0 ratings