Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From the post-receive file:

# This script is run after receive-pack has accepted a pack and the
# repository has been updated.  It is passed arguments in through stdin
# in the form
#  <oldrev> <newrev> <refname>
# For example:
#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master

But when I test it with echo "$1 $2 $3", I get a blank line only. Does any-one know why?

share|improve this question

Here's a simple example that confirms koumes21s answer. I made post-receive a Python script with the following code:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys

print "ARGS:", sys.argv

a =
(old, new, ref) = a.split()
print "Old: %s" % old
print "New: %s" % new
print "Ref: %s" % ref

Here's the output after a push. Notice that "ARGS" only reports the name of the script and none of the stdin.

inneralienmbp$ git push
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 299 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
remote: ARGS: ['hooks/post-receive']
remote: Old: 5c9f9a43132516040200ae76cc2f4f2cad57d724
remote: New: 95e0e2873eaad2a9befa2dff7e2ce9ffdf3af843
remote: Ref: refs/heads/master
To /Users/tweaver/test2/test.git/
   5c9f9a4..95e0e28  master -> master

Thanks koumes21!

share|improve this answer

That is because the arguments are passed through the stdin, not through the command line arguments. This is because there can be multiple changes which are then passed to your script as multiple lines. So you can either use the read command or get the input from /dev/stdin.

share|improve this answer

Here is a post on stack which solves this problem.

Here is a simple version for what you are trying to get:

read oldrev newrev ref
echo "$oldrev"
echo "$newrev"
echo "$ref"

Here is the version that I use for my CI server and email hook

read oldrev newrev ref
echo "$oldrev" "$newrev" "$ref" | . /usr/share/git-core/contrib/hooks/post-receive-email

if [ "refs/heads/qa" == "$ref" ]; then
  # Big Tuna YO!
  wget -q -O - --connect-timeout=2
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.