pre-push
# 1.在项目.git\hooks目录里面编写pre-push文件
#!/bin/sh
echo "-----------------------------当前操作是: pre-push-----------------------------"
# 第二个远程仓库名称
GITLAB_REMOTE_NAME="GITLAB_REMOTE"
GITLAB_REMOTE_URL="GITLAB_REMOTE_URL"
# 配置第二个远程仓库(如果尚未配置)
if ! git remote | grep -q "$GITLAB_REMOTE_NAME"; then
echo "Configuring $GITLAB_REMOTE_NAME remote..."
git remote add $GITLAB_REMOTE_NAME $GITLAB_REMOTE_URL
fi
# 获取当前分支名称
current_branch=$(git rev-parse --abbrev-ref HEAD)
# 输出当前分支名称
echo "当前分支是: $current_branch"
# 推送代码
git push $GITLAB_REMOTE_NAME $current_branch:$current_branch --force
if [ $? -ne 0 ]; then
echo "git push failed......."
exit 1
fi
# 允许推送
exit 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
上次更新: 2024/08/07, 16:19:09