git repo on production server: What is the step after setting up the bare repository?

I have created a bare git repo on my EC2 instance, and I have pushed a branch from my dev machine to it. I can run git log on the server now and it looks up-to-date with everything.

The dev machine now has two remotes, one “origin” is Bitbucket.org repo where the code lives, and the second “ec2” is the remote I would push to in order to deploy the code. It looks like whenever I push to “ec2” it will basically sync the repo with whatever I grabbed off of Bitbucket. Which is good, though at the back of my mind I’m wondering what I’d have to do differently to construct a different history without the intermediate content. (not important.)

  • Failed to add the host to the list of known hosts - Accidentally removed all files from my .ssh folder
  • Clean install on AWS EC2 from GIT
  • Amazon EC2, deployment with capistrano, how to?
  • AWS ec2 git clone or pull not working and no error message
  • Initialize Git Repository From Web Interface
  • Jenkins Installation Wizard Error
  • However on the server, the repo is a bare repo and has no working tree.

    What is the proper way to get the server to auto-deploy the webapp?

    I’d like someone to help me compare and contrast these two methods:

     ... inside the bare repo on the server ... 
    $ cat > hooks/post-receive
    #!/bin/sh
    GIT_WORK_TREE=/home/ec2-user/www/webserver-works-off-this-dir
    export GIT_WORK_TREE
    git checkout -f
    

    Alternatively I think it could make sense to set up a separate git repo, i.e.

     ... also on the server ... 
    $ cd /home/ec2-user/www/
    $ git clone # ??? How do I clone from localhost bare repo?
     ... presumably set the post-receive hook in the bare-repo to cd to *this* dir and run git checkout or pull or something... 
    

    Oh, also, what does git checkout -f do? Force overwrite checkout the latest chronological commit? I think there is something implicit that I’m uncertain of. I guess a push operation must be “attached” to some commit, and this would be the commit in question.

  • Is there a way to add a link to the current repo in Github README.md?
  • TortoiseGIT + Gitolite 3
  • Use Ant project as Gradle subproject
  • Can I load one .gitconfig file from another?
  • manage multiple github repos from the same system and different user names
  • Getting file to add that was previously on ignore-paths
  • One Solution collect form web for “git repo on production server: What is the step after setting up the bare repository?”

    The post-receive hook is a good solution.

    The other alternative is to setup a second non-bare repo and cd into that repo in order to pull from the first bare repo. I explain it in “Is --bare option equal to core.bare config in Git?”.

    As eis comments, both solutions are good if you want to push directly to the EC2 server git repo.
    Pulling directly the BitBucket repo from a git session in EC2 can work too.

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