git本地仓库 连接 远程github仓库

github 使用笔记

1.申请github账号

申请地址:https://github.com/join

2.添加SSH Key

  1. 本地生成SSH Key秘钥对

ssh-keygen -t rsa -C “your@mail.com”

  1. 公钥文件id_rsa.pub里的内容添加到github SSH keys

cat ~/.ssh/id_rsa.pub

将内容复制进https://github.com/settings/ssh/newKey内容里

  1. 测试

ssh -T git@github.com

出现一下内容,表示连接成功:
Hi {your github name}! You’ve successfully authenticated

3.在github上添加仓库

  1. 创建仓库
    在这里插入图片描述

  2. 复制仓库地址
    在这里插入图片描述

本次测试地址:git@github.com:morningcat2018/github-demo.git

4.git本地仓库连接远程github仓库

git config --global user.name "morningcat"
git config --global user.email "morningcat2018@qq.com"


mkdir github-demo
cd github-demo 

# 初始化仓库
git init

# 提交
touch git.txt
git add git.txt 
git commit -m 'add git.txt'

# 添加远程仓库
git remote add origin git@github.com:morningcat2018/github-demo.git

# 拉取
git pull origin master --allow-unrelated-histories 
git fetch
git pull origin master

# 推送
git push -u origin master

此时本地的git记录已推送到远程github仓库了

参考文档

  1. 遇到问题
    fatal: 拒绝合并无关的历史

问题详情:

git pull origin master
来自 github.com:morningcat2018/spring-bpp-demo
 * branch            master     -> FETCH_HEAD
fatal: 拒绝合并无关的历史

解决方案:
https://blog.csdn.net/lddtime/article/details/77817317


5.本地版本回退

git log

找到自己要撤回到的版本

git reset --hard <commit_id>


6.Gitee 单个文件不能超过100M

以及单个账户的总容量不能超过5G

7.Git配置多个SSH-Key

Git配置多个SSH-Key

背景
当有多个git账号时,比如:

a. 一个gitee,用于公司内部的工作开发;
b. 一个github,用于自己进行一些开发活动;

解决方法

生成一个公司用的SSH-Key
$ ssh-keygen -t rsa -C ‘xxxxx@company.com’ -f ~/.ssh/gitee_id_rsa
生成一个github用的SSH-Key
$ ssh-keygen -t rsa -C ‘xxxxx@qq.com’ -f ~/.ssh/github_id_rsa
在 ~/.ssh 目录下新建一个config文件,添加如下内容(其中Host和HostName填写git服务器的域名,IdentityFile指定私钥的路径)

gitee

Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa

github

Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

4.用ssh命令分别测试

$ ssh -T git@gitee.com
$ ssh -T git@github.com

这里以gitee为例,成功的话会返回下图内容

输入图片说明

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值