Digital Ocean git bare repo

I am trying to setup my own production environment on digital ocean with ubuntu, rails and git.

I have followed this and this tutorial among others.

  • Git clone to any server? (even without git installed)
  • Unable to resolve “unable to get local issuer certificate” using git on Windows with self-signed certificate
  • git-commit gives no output and nothing is committed
  • “git commit --amend -c <commit>” not saving changes
  • invisible git meta commit
  • How to delete a file in remote repository ONLY?
  • They all instruct to create the repository as bare, i.e.:

    mkdir site.git && cd site.git
    git init --bare
    

    Problem is that when I push from my local computer, I got the error:

    This operation must be run in a work tree

    I looked into it and it seems that the cause is that the repo is bare.

    In my post receive file I have:

    #!/bin/sh
    git --work-tree=/home/rails/myapp --git-dir=/var/repo/site.git checkout -f
    

    So I am confused. I suppose that I could initialize the repo as non bare instead. But why every tutorial suggests to initialize it as bare if then it causes that error?

  • Git - Pull from one remote repo, push to another: can I push names of remotes?
  • Compilation error - package com.google.gson not found in Redhat “Openshift” application
  • Using git rebase and git merge to set up a good team workflow
  • I interrupted a clone operation. How can I clone again without errors?
  • How did I screw up this very simple .gitignore file?
  • Specify Git Rename after changes
  • One Solution collect form web for “Digital Ocean git bare repo”

    If you are making a git push, you must do so from a normal git repo, meaning a local repo on your workstation (pushing indeed to a bare repo)

    cd /path/to/my/local/repo
    
    git init .
    git add -A
    git commit -m "my first commit"
    git remote add origin /usr/bare/repo
    git push -u origin master
    

    In your case, you cannot push directly from where the post-receive hook does a checkout, unless you mention in your git push command where the git repo is (bare or not)

    cd /home/rails/myapp
    git --work-tree=/home/rails/myapp --git-dir=/var/repo/site.git push -u origin master
    

    (and this assume /var/repo/site.git does include a remote named origin)

    Git Baby is a git and github fan, let's start git clone.