Erstellen eines Git-Repositorys aus einem Produktionsordner

Ich habe eine Maschine mit einer Produktionswebsite. Ich möchte ein Git-Repository auf dieser Maschine erstellen, um die Website mit Git zu verwalten.

Also habe ich als erstes ein leeres .git-Repository in der Produktionsmaschine erstellt:

mkdir repos
cd repos
mkdir production.git
cd production.git
git init --bare

In diesem Repository unter Hooks / Post-Receive habe ich die folgenden Zeilen hinzugefügt:

#!/bin/sh
GIT_WORK_TREE=/var/www/production_website git checkout -f

Dann habe ich den Ordner mit meiner Produktionswebsite auf meinen lokalen Computer heruntergeladen und git gestartet:

cd production_website
git init

Danach habe ich das erste Commit gemacht:

git add .
git commit -m "first commit"

Und schließlich habe ich das Remote-Repository hinzugefügt und meinen ersten Push durchgeführt:

git remote add origin ssh://[email protected]/repos/production.git
git push origin master

Aber wenn ich den Push mache, wird mir die folgende Fehlermeldung angezeigt:

remote: fatal: This operation must be run in a work tree

Was ausgelöst wird, wenn der Post-Receive-Hook aktiviert wird.

Irgendwelche Vorschläge, was ich falsch machen könnte?

AKTUALISIEREN:

Im ersten Schritt beim Erstellen eines leeren .git-Repositorys in der Produktionsmaschine, wenn ich es verwendegit init anstattgit init --bare Ich erhalte diese Fehlermeldung, wenn ich einen Push mache:

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'.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage