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

博文目录


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

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

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

查看仓库绑定情况

git remote -v

origin  [email protected]:mrathena/code.study/python.apex.weapon.auto.recognize.and.suppress.git (fetch)
origin  [email protected]:mrathena/code.study/python.apex.weapon.auto.recognize.and.suppress.git (push)

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

git remote set-url --add origin [email protected]:mrathena/python.apex.weapon.auto.recognize.and.suppress.git
git remote -v

origin  [email protected]:mrathena/code.study/python.apex.weapon.auto.recognize.and.suppress.git (fetch)
origin  [email protected]:mrathena/code.study/python.apex.weapon.auto.recognize.and.suppress.git (push)
origin  [email protected]: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 [email protected] 检查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 [email protected] , 根据提示输入 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 将成功

猜你喜欢

转载自blog.csdn.net/mrathena/article/details/128173637
今日推荐