返回顶部

pzzning

导航

本地Git与github连接/上传配置

参照:http://www.runoob.com/w3cnote/git-guide.html


一、本地与githup连接配置
1、本地创建ssh key:

$ ssh-keygen -t rsa -C "your_email@youremail.com"

 后面的your_email@youremail.com改为你在github上注册的邮箱,之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。
成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
如:

ssh-keygen -t rsa -C "969083154@qq.com"

2、Githup上添加ssh key:
Account Settings(账户配置) --> SSH Keys --> Add SSH Key (title随便填,粘贴在你电脑上生成的key)

3、连接验证:

$ ssh -T git@github.com
Hi pzzning! You've successfully authenticated, but GitHub does not provide shell access.

如果是第一次的会提示是否continue,输入yes就会看到:You've successfully authenticated, but GitHub does not provide shell access 。

这就表示已成功连上github。

二、本地仓库上传到github:
1、本地用户名和email配置(初始化配置过了,本步骤可以忽略)
--- 本地仓库传到github上,github每次commit都会记录他们

$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"

如:

$ git config --global user.name "pzzning"
$ git config --global user.email "969083154@qq.com"

 2、进入要上传的仓库,右键git bash,添加远程地址:

$ git remote add origin git@github.com:yourName/yourRepo.git
$ git push -u origin master

 如:

$ git remote add Git-test git@github.com:pzzning/Git-test.git
$ git push -u Git-test master

 后面的yourName和yourRepo表示你再github的用户名和刚才新建的仓库,加完之后进入.git,打开config,这里会多出一个remote "origin"内容,这就是刚才添加的远程地址,也可以直接修改config来配置远程地址。

三、配置实例:

1、Githup配置:
新建一个Git-test仓库:Create a new repository

2、本地配置:

$ mkdir Git-test                                 # 创建测试目录
$ cd Git-test/                                   # 进入测试目录
$ echo "# 宁宁 Git 测试" >> README.md             # 创建 README.md 文件并写入内容
$ ls                                             # 查看目录下的文件
README
$ git init                                       # 初始化
$ git add README.md                              # 添加文件
$ git commit -m "添加 README.md 文件"             # 提交并备注信息
[master (root-commit) 0205aab] 添加 README.md 文件
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

 3、提交到 Github

$ git remote add Git-test git@github.com:pzzning/Git-test.git
$ git push -u Git-test master

4、结果确认:

查看Github上是否有新提交的文件。

 

posted on 2018-09-30 19:14  pzzning  阅读(287)  评论(0编辑  收藏  举报