I am trying to setup push to deploy on a vps (a digitalocean droplet), for this I created a repo and initiated it with
mkdir demorepo && cd demorepo
mkdir demo.git && cd demo.git
git init --bare
git --work-tree=/var/www/demo --git-dir =/var/demorepo/demo.git checkout -f
chmod +x post-receive
git remote add live ssh://firstname.lastname@example.org/var/demorepo/demo.git
git push live master
To ensure hooks work properly you should "debug" them by executing the commands manually.
If/when you get them working manually then you can think about putting them into a hook script.
In this specific question I would expect the command to fail with this error message:
fatal: Not a git repository: '=/var/demorepo/demo.git'
The reason for this is that you've unintentionally added a space after the
git --work-tree=/var/www/demo --git-dir =/var/demorepo/demo.git checkout -f ^ | +-- here
Remove that space and you should be good to go.
You could also remove the equal sign as the following two variants are the same:
--git-dir=x --git-dir x
But you can't combine the two as in your case the equal sign is part of the path that git tries to locate, hence the error.