Git不同平台仓库更新代码
# Git 不同平台仓库更新代码
- gitee上
https://gitee_AAAA.git
的代码仓库地址 - 以及克隆到gitlab的
https://gitlab_AAAAA.git
的代码仓库地址
# 场景
gitee上代码有更新,期望同步代码到gitlab上。
# 手动操作步骤
# Step 1: 在自己电脑上克隆 Gitee 仓库为裸仓库
git clone --bare https://gitee_AAAA.git
# 进入裸仓库目录
cd gitee_AAAA.git
# Step 2: 添加 GitLab 作为远程仓库
git remote add gitlab https://gitlab_AAAAA.git
# Step 3: 从 Gitee 拉取 dev 分支的最新更新
git fetch origin dev
# Step 4: 推送到 GitLab 的 dev 分支
git push gitlab dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
这样就完成了gitee dev 分支的代码更新到gitlab dev 分支的操作。
全仓库完整同步,不会删除gitlab上新建的分支。
注意分支同名,如果凑巧,你在gitlab建立的分支叫 123 ,同时gitee上突然有了一个 123 分支,那么gitlab上的就被覆盖掉了!!!!!!
注意分支同名,如果凑巧,你在gitlab建立的分支叫 123 ,同时gitee上突然有了一个 123 分支,那么gitlab上的就被覆盖掉了!!!!!!
注意分支同名,如果凑巧,你在gitlab建立的分支叫 123 ,同时gitee上突然有了一个 123 分支,那么gitlab上的就被覆盖掉了!!!!!!
注意分支同名,如果凑巧,你在gitlab建立的分支叫 123 ,同时gitee上突然有了一个 123 分支,那么gitlab上的就被覆盖掉了!!!!!!
#!/bin/bash
# Step 1: 克隆 Gitee 仓库为裸仓库
git clone --bare https://gitee_AAAA.git
cd RuoYi-Vue-Plus.git
# Step 2: 添加 GitLab 作为远程仓库
git remote add gitlab https://gitlab_AAAAA.git
# Step 3: 从 Gitee 拉取最新更新
git fetch origin
# Step 4: 推送更新到 GitLab
# 推送所有分支
for branch in $(git branch -r | grep "origin/" | sed 's/origin\///'); do
git push gitlab $branch:$branch
done
# 推送所有标签
git push gitlab --tags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
编辑 (opens new window)
上次更新: 2025/04/25, 09:31:01