I have a machine with a production website, I want to create a git repository in that machine in order to manage the website using git.
So the first thing I did was to create an empty .git repository in the production machine:
mkdir repos
cd repos
mkdir production.git
cd production.git
git init --bare
In this repository under hooks/post-receive I've added the following lines:
#!/bin/sh
GIT_WORK_TREE=/var/www/production_website git checkout -f
Then I've downloaded the folder with my production website into my local machine and started git:
cd production_website
git init
After that I made the first commit:
git add .
git commit -m "first commit"
And finally I've added the remote repository and made my first push:
git remote add origin ssh://myuser@productionmachine.com/repos/production.git
git push origin master
But when I make the push it gives me the following error message:
remote: fatal: This operation must be run in a work tree
Which it's triggered when the post-receive hook it's activated.
Any suggestions of what I might be doing wrong?
UPDATE:
In the first step, when creating an empty .git repository in the production machine, if I use git init
instead of git init --bare
I get this error message when making a push:
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
I would rather keep the repo bare, then in the post-receive hook
That is: