I run a git server and have some pre-receive hooks set up. When someone pushes and this hook gets called, I would like to know which branch they are on.
Is there some sort of series of git commands that will allow me to do this? It is absolutely crucial for what I need to do.
Git push doesn't assume any given branch is checked out locally; in fact, it could be a bare repository you're pushing. As Etan Reisner mentioned, your script will automatically receive a list of ref updates on stdin , though, which can be used to tell which branches have new commits.
Here is a simple example of pre-receive hook
#! /bin/sh
while read oldrev newrev refname
do
echo "$oldrev $newrev $refname"
done
refname
contains the target branch refspec on the server (ie refs/heads/master )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.