本地git仓库连接GitHub
一、设置name和email
$ git config --global user.name "***"
$ git config --global user.email "***@***.com"
二、生成SSH密钥
查看是否已经有了密钥,windows系统:’C:/Users/####/.ssh’,如果没有此文件夹,则生成新的key:
$ ssh-keygen -t rsa -C "***@***.com"
Generating public/private rsa key pair. Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):
回车选择默认路径。
到GitHub提交密钥
- 找到.ssh文件夹,用txt或者其他文本编辑器打开”id_rsa.pub”,复制内容。
- 打开github,到设置里找到add SSH Key,粘贴刚才复制的密钥。如果之前已经添加了的话,会提示密钥正在使用。
在GitHub上创建新项目,克隆到本地
在github首页站到”New repository”,创建新仓库 Demo
clone到本地
$ git clone https://github.com/***/Demo.git
- 在本地Demo目录下创建README.md文件,并提交。注意步骤,commit后并没有正真提交,还需要push
$ git touch README.md
$ git add README.md
$ git commit -m 'first commit'
- 完成push操作
$ git push origin master
在本地创建库,上传到github(神坑)
(1)新建文件夹helloworld,并进入路径,
$ mkdir helloworld
$ cd ~/helloworld
$ git init
执行完init后,就完成了仓库初始化。
(2)添加README文件
$ git touch README.md
$ git add README.md
$ git commit -m 'add README'
(3)为版本库添加民委origin的远程库
$ git remote add origin git@github.com:kourou1034/helloworld
(4)执行推送命令
$ git push -u origin master
这一步有点坑,一直报错:
remote: Repository not found.
fatal: repository 'https://github.com/kourou1034/helloworld.git/' not found
解决方法是先在github上创建helloworld仓库,不要添加README等任何文件,然后再次执行推送命令。(这样做感觉和上一节没什么区别了。。捂脸)