Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 458|回复: 0
打印 上一主题 下一主题

双库推送

[复制链接]

1228

主题

1997

帖子

7580

积分

认证用户组

Rank: 5Rank: 5

积分
7580
跳转到指定楼层
楼主
发表于 2023-10-30 16:27:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
公司仓库origin 的 master分支关联移动仓库 cjxtOrigin的master分支设置方法
先进入到origin的master分支
拉取最新代码
git pull

查看目前关联的远程仓库
$ git remote -v
origin  https://192.168.8.7/123pc-client/Yun_ClientWin.git (fetch)
origin  https://192.168.8.7/123pc-client/Yun_ClientWin.git (push)

添加新的远程仓库

git remote add cjxtOrigin master

即添加新仓库 cjxtOrigin 并指定新仓库的目标分支 master

再查看关联的远程仓库
$ git remote -v
cjxtOrigin      master (fetch)
cjxtOrigin      master (push)
origin  https://192.168.8.7/123pc-client/Yun_ClientWin.git (fetch)
origin  https://192.168.8.7/123pc-client/Yun_ClientWin.git (push)

发现已经新增加了远程仓库,但还没设置仓库地址,设置一下仓库地址
git remote set-url cjxtOrigin http://cjxt.tools.bigcloudsys.cn ... rt/pc/pc_client.git

再查看一下
$ git remote -v
cjxtOrigin      http://cjxt.tools.bigcloudsys.cn ... rt/pc/pc_client.git (fetch)
cjxtOrigin      http://cjxt.tools.bigcloudsys.cn ... rt/pc/pc_client.git (push)
origin  https://192.168.8.7/123pc-client/Yun_ClientWin.git (fetch)
origin  https://192.168.8.7/123pc-client/Yun_ClientWin.git (push)

已经设置完成


推动到云端分支

git checkout 本地分支名
git push <远程主机名> <本地分支名>:<远程分支名>

eg:

git checkout master
git push cjxtOrigin master:master
cjxtOrigin 是你想push的那个远程库,master是你想push的那个分支,master是push到远程的那个分支。



$ git push cjxtOrigin master:master
To http://cjxt.tools.bigcloudsys.cn ... rt/pc/pc_client.git
! [rejected]            master -> master (fetch first)
error: failed to push some refs to 'http://cjxt.tools.bigcloudsys.cn/gitlab/cloudTecSupport/pc/pc_client.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

移动库和本地库有冲突,强制推送

$ git push -f cjxtOrigin master:master
Enumerating objects: 1779, done.
Counting objects: 100% (1490/1490), done.
Delta compression using up to 4 threads
Compressing objects: 100% (803/803), done.
Writing objects: 100% (1296/1296), 2.31 MiB | 2.32 MiB/s, done.
Total 1296 (delta 1018), reused 751 (delta 493), pack-reused 0
remote: Resolving deltas: 100% (1018/1018), completed with 148 local objects.
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To http://cjxt.tools.bigcloudsys.cn ... rt/pc/pc_client.git
! [remote rejected]     master -> master (pre-receive hook declined)
error: failed to push some refs to 'http://cjxt.tools.bigcloudsys.cn/gitlab/cloudTecSupport/pc/pc_client.git'

这是因为项目分支master设置了保护所致,是为了防止别人乱提交代码设置的

可以到项目的Settings页面下找到 Protected Branches,有如下两种解决方法

1.可以直接点该分支旁的Unprotect按钮,解除保护,但是这种方法不推荐

2.第二种方法是在Allowed to push下选择允许那些角色或具体那些用户可以提交,在这里可以选择你自己

设置完毕后再重新提交就成功了。

如果已存在的拉取失败,执行这个命令  git pull --allow-unrelated-histories



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-4-29 16:46 , Processed in 0.080252 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表