Here's my current hook in a bare repo that lives in the company's server:
git push origin master
This hooks pushes to Assembla.
What i need is to push only one branch (master, ideally) when someone pushes changes to that branch on our server, and ignore pushes to other branches. Is it possible to select the branch from a bare repo and push only that branch to Assembla?
解决方案
A post-receive hook gets its arguments from stdin, in the form . Since these arguments are coming from stdin, not from a command line argument, you need to use read instead of $1 $2 $3.
The post-receive hook can receive multiple branches at once (for example if someone does a git push --all), so we also need to wrap the read in a while loop.
A working snippet looks something like this:
#!/bin/bash
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" == "$branch" ]; then
# Do something
fi
done