Automatically forward certain pushes to other repositories

suggest change

post-receive hooks can be used to automatically forward incoming pushes to another repository.

$ cat .git/hooks/post-receive

#!/bin/bash

IFS=' '
while read oldrev newrev refname
do

  echo "$refname" | egrep '^refs\/heads\/[A-Z]+-[0-9]+$' >/dev/null && {
    ref=`echo $refname | sed -e 's/^refs\/heads\///'`
    echo Forwarding feature branch to other repository: $ref
    git push -q --force other_repos $ref
  }

done

post-receive reads oldrev newrev refname on stdin. In this example, the egrep pattern matches a branch name such as JIRA-12345. Leave that test out if you want to forward every branch. The receiving repository needs a remote named other_repos.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents