博文目录
文章目录
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.comUser GitHub 邮箱Hostname ssh.github.comPreferredAuthentications publickeyIdentityFile ~/.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.comAre you sure you want to continue connecting (yes/no/[fingerprint])? yesWarning: 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 将成功
版权归原作者 mrathena 所有, 如有侵权,请联系我们删除。