Git 一份代码如何同时提交并推送到两个仓库

博文目录


Git 一份代码如何同时提交并推送到两个仓库

Git - 将一个项目同时从本地推送到 GitHub 和 Gitee

一份代码如何同时提交并推送到两个仓库, 需要明确从哪个仓库拉取代码

查看仓库绑定情况

git remote -v

origin  git@e.coding.net:mrathena/code.study/python.apex.weapon.auto.recognize.and.suppress.git (fetch)
origin  git@e.coding.net:mrathena/code.study/python.apex.weapon.auto.recognize.and.suppress.git (push)

再绑定另外一个远程仓库, 该仓库只推不拉

git remote set-url --add origin git@github.com:mrathena/python.apex.weapon.auto.recognize.and.suppress.git
git remote -v

origin  git@e.coding.net:mrathena/code.study/python.apex.weapon.auto.recognize.and.suppress.git (fetch)
origin  git@e.coding.net:mrathena/code.study/python.apex.weapon.auto.recognize.and.suppress.git (push)
origin  git@github.com:mrathena/python.apex.weapon.auto.recognize.and.suppress.git (push)

这时候执行推送, 大概率只能成功推到第一个仓库, 后绑定的仓库会拒绝, 要求先获取一次

可以执行 git push -f 强制推送一次, 后续 git push 就正常了

其他情况见参考文章

GitHub ssh: connect to host github.com port 22: Connection timed out

ssh: connect to host github.com port 22: Connection refused

如果 GitHub push 时出现如下内容, 包含 ssh: connect to host github.com port 22: Connection timed out 字样, 无法 push

ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

首先输入 ssh -T git@github.com 检查SSH是否能够连接成功, 如果提示 ssh: connect to host github.com port 22: Connection timed out 则说明 22 端口可能真的不通了, 可以通过下面方法换成 443 端口

  • C:\Users\mrathena\.ssh 中新建文本文件 config, 内容如下
    Host github.com
    User GitHub 邮箱
    Hostname ssh.github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_ecdsa # id_rsa 可能已经被 GitHub 封了, 我现在用的是 id_ecdsa 
    Port 443
    
  • 再次输入 ssh -T git@github.com , 根据提示输入 yes, 提示 You've successfully authenticated 则配置成功
    The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
    ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
    This host key is known by the following other names/addresses:
        C:\Users\mrathena/.ssh/known_hosts:2: github.com
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.
    Hi mrathena! You've successfully authenticated, but GitHub does not provide shell access.
    
  • 再次 push 将成功
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值