• Git同时配置和提交代码到Github和Gitee


    配置 Github 和 Gitee

    1. 创建ssh钥匙
      注:创建时不需要输入密码,直接回车。

      ssh-keygen -t rsa -C '邮箱' -f ~/.ssh/id_rsa_github
      
      • 1
      ssh-keygen -t rsa -C '邮箱' -f ~/.ssh/id_rsa_gitee
      
      • 1
    2. 添加ssh钥匙到github和gitee

      • Github添加钥匙
        钥匙文件:C:\Users\用户名\.ssh 下的 id_rsa_github.pub
        添加钥匙的路径:头像 -> Settings -> SSH and GPG keys -> SSH keys -> New SSH key
        操作:将 id_rsa_github.pub 文件中的内容复制到如下的所示的 Key 中
        在这里插入图片描述

      • Gitee添加钥匙
        钥匙文件:C:\Users\用户名\.ssh 下的 id_rsa_gitee.pub
        添加钥匙的路径:头像 -> 设置 -> ssh公匙
        操作:将 id_rsa_gitee.pub 文件中的内容复制到如下的所示的 Key 中
        在这里插入图片描述

    3. 添加配置文件
      C:\Users\用户名\.ssh 中创建文件 config 写入如下内容

      # github
      Host github.com
      HostName github.com
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/id_rsa_github
      
      # gitee
      Host gitee.com
      HostName gitee.com
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/id_rsa_gitee
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
    4. 测试配置成功

      ssh -T git@gitee.com
      
      • 1
      ssh -T git@github.com
      
      • 1

      在这里插入图片描述
      到此处,git同时配置github和gitee成功!!!

    同时提交代码到 Github 和 Gitee

    1. 初始化一个项目 git init

    2. 配置信息
      打开项目中的 .git文件夹下的 config 文件,写入如下内容。
      注:.git默认是一个隐藏文件夹,需要允许访问隐藏文件才能看到此文件。

      [core]
          repositoryformatversion = 0
          filemode = false
          bare = false
          logallrefupdates = true
          symlinks = false
          ignorecase = true
      
      [remote "github"]
          url = https://github.com/a-jingchao/dim-star.git
          fetch = +refs/heads/*:refs/remotes/origin/*
      
      [remote "gitee"]
          url = https://gitee.com/a-jingchao/dim-star.git
          fetch = +refs/heads/*:refs/remotes/origin/*
      
      [branch "master"]
          remote = origin
          merge = refs/heads/master
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
    3. 测试成功

      git remote
      
      • 1

      在这里插入图片描述

    4. 其他操作 git add 、git commit

    5. 提交代码到仓库

      git push github master
      
      • 1
      git push gitee master
      
      • 1

    大功告成!!!!

  • 相关阅读:
    CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)
    【HBU】数据结构第一次月测题(线性结构)
    一个类在什么时候会被加载
    论文题目:深度学习在自然语言处理中的应用研究
    lotus 2k 测试网 多签钱包改为单签
    支付宝 v3 验签如何实现
    【题型总结】找到第n个自定义数 | 丑数系列 + 神奇数字
    《软件方法》第1章2023版连载(07)UML的历史和现状
    狄兰·托马斯诗合集▷Do not go gentle into that good night
    ExtJS 数据处理-Ext.data.field.field类型
  • 原文地址:https://blog.csdn.net/weixin_52372879/article/details/126517824