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

版权声明:转载请注明出处 https://blog.csdn.net/u013837825/article/details/88608203

github 使用笔记

1.申请github账号

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

2.添加SSH Key

  1. 本地生成SSH Key秘钥对

ssh-keygen -t rsa -C "[email protected]"

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

cat ~/.ssh/id_rsa.pub

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

  1. 测试

ssh -T [email protected]

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

3.在github上添加仓库

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

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

本次测试地址:[email protected]:morningcat2018/github-demo.git

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

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 [email protected]: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

猜你喜欢

转载自blog.csdn.net/u013837825/article/details/88608203