自动将主代码库上的更改同步到gitlab中的分叉代码库

时间:2016-09-15 11:50:26

标签: git gitlab gitlab-ci gitlab-ci-runner gitlab-omnibus

我的gitlab帐户中有两个项目,名为zip / production(master)和map / production(从master分叉)。每当我对zip / production进行更改时,都应该自动更新到map / production,但是应该保留map / production中的其他文件。这可能吗?

1 个答案:

答案 0 :(得分:0)

不仅可行,而且非常简单!

# .git/hooks/post-receive on the remote:


#!/usr/bin/bash

IFS=' '
while read local_ref local_sha remote_ref remote_sha
do

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

done

此示例仅采用分支的子集(采用Jira问题格式,XYZ-1234)并将其转发到第二个存储库。当然,您可以将条件转移到一切。