title: Creating a git repository from a production folder
body: <p>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.</p>
  
  <p>So the first thing I did was to create an empty .git repository in the production machine:</p>
  
  <pre><code>mkdir repos
  cd repos
  mkdir production.git
  cd production.git
  git init --bare
  </code></pre>
  
  <p>In this repository under hooks/post-receive I've added the following lines:</p>
  
  <pre><code>#!/bin/sh
  GIT_WORK_TREE=/var/www/production_website git checkout -f
  </code></pre>
  
  <p>Then I've downloaded the folder with my production website into my local machine and started git:</p>
  
  <pre><code>cd production_website
  git init
  </code></pre>
  
  <p>After that I made the first commit:</p>
  
  <pre><code>git add .
  git commit -m "first commit"
  </code></pre>
  
  <p>And finally I've added the remote repository and made my first push:</p>
  
  <pre><code>git remote add origin ssh://myuser@productionmachine.com/repos/production.git
  git push origin master
  </code></pre>
  
  <p>But when I make the push it gives me the following error message:</p>
  
  <pre><code>remote: fatal: This operation must be run in a work tree
  </code></pre>
  
  <p>Which it's triggered when the post-receive hook it's activated.</p>
  
  <p>Any suggestions of what I might be doing wrong?</p>
  
  <p><strong>UPDATE</strong>: </p>
  
  <p>In the first step, when creating an empty .git repository in the production machine, if I use <code>git init</code> instead of <code>git init --bare</code> I get this error message when making a push:</p>
  
  <pre><code>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'.
  </code></pre>