2

Possible Duplicate:
Git Post-Receive Hook for Website Staging

I started learning Git today and I'm stuck on one thing.

When I push my local production repository to my remote staging repository, I would like to immediately be able to view my newly pushed files live. When I try to look for my files in my remote repository (via an FTP client), I can't find them.

Do I need to perform some advanced Git magic in order to achieve this (hooks?)? What is best practice for this situation?

Again, I'm new to Git and don't fully understand the concept yet. Maybe it's worth noting that I use a Webfaction Git application for the remote repository.

Edit: I saw this topic on SO, and I know how to create a post-commit hook but I have no idea what to put in the shell script.

Community
  • 1
  • 1
Jesse
  • 479
  • 7
  • 22

2 Answers2

2

First off, you don't want to use a post-commit hook - that's a client-side hook. The server-side hook you want will be either post-receive or update (depending on whether you're using branches).

See: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

In your hook script, you should chdir to the server document root and run a git pull. Also, at the top of the script, make sure to include

unset GIT_DIR

otherwise git will confuse itself when you try to pull.

ax.
  • 53,672
  • 7
  • 72
  • 66
Ryan P
  • 14,118
  • 27
  • 48
1

Assuming you create a post-commit post-receive or update hook on a machine with BASH, try something like this:

#!/bin/bash

cd /your/git/repository/directory
git checkout -f

...

A couple notes:

  • A little information about what is happening. When pushing to a remote repository, git does not automatically check out the new code. So, the post-commit hook needs to check out the latest code on the branch.
  • You may need to tell the git repository on your server to allow you to push to the checked-out branch. Running this command in the git repo on that server should do the trick:

    git config receive.denycurrentbranch false
    
James
  • 148
  • 5