笔记-git与github的交互初识

这是我根据参考博客自己动手做的一个利用git和github分别在本地和github网络端做了两个仓库,以及把文件存入这两个仓库的经验总结。


由于从word转为博客导致某些格式和内容丢失,故提供word链接
链接: https://pan.baidu.com/s/1bQmnr4 密码: tzpe
参考博客:http://blog.csdn.net/oldinaction/article/details/49704969


信息
Administrator@USER-20170827CK MINGW64 /e
信息:在e盘

Administrator@USER-20170827CK MINGW64 /e/Demo (master)
信息:在e盘 管理员模式

本地仓库操作
理解目录与仓库:
比喻:目录中存放的时实体,仓库中存放的是账本。
.git文件夹下一堆文件相当于账簿,起着管理作用。因为目前还没有实际使用,所以暂不了解其机能。
所以目录向仓库的提交,抽象理解为目录中的东西存入了仓库,客观理解为做了注册的事。

1-创建仓库
git init
初始化git仓库

2-提交代码
2.1-从目录中提交给“缓存”
git add test.html
从当前目录找到test.html添加到git仓库

git add .
把当前目录下所有文件添加到git仓库

2.2-“按下确认键”把“缓存”提交给仓库
git commit –m “第一次提交”
确认提交操作,然后得到反馈信息:
[master (root-commit) 5f840c6] 第一提交
4 files changed, 64 insertions(+)
create mode 100644 config.yaml
create mode 100644 index.wsgi
create mode 100644 test.html
create mode 100644 weixinInterface.py

远程仓库操作
1.在git本地全局使用邮箱账号生成id_rsa.pub文件
$ ssh-keygen -t rsa -C “csuherui@sina.com”
在git里生成公钥文件,用来连接github(中间连敲三次回车)
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):(第一次)
Created directory ‘/c/Users/Administrator/.ssh’.
Enter passphrase (empty for no passphrase):(第二次)
Enter same passphrase again:(第三次)
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:jjcD5o2RB0vfDdfd2Ry5+jKJB7AArL6aLiRwpsHShCQ csuherui@sina.com
The key’s randomart image is:
+—[RSA 2048]—-+
|Eo . ..|
|o . o . +=|
|.o . + ….*|
|+.+. . * o + . |
|o=. * S + . . |
|o. . o O … |
|o . + * o o |
|. .. . o . = . |
|o+. . o |
+—-[SHA256]—–+
在C:\Users\Administrator.ssh目录下可以看到

这是公钥文件。

2.在github用git本地全局id_rsa.pub文件生成SSH keys公钥

前面先在github上建一个仓库,这里我事先建了两个仓库:

3.在git本地尝试连接github
ssh git@github.com
如果连接成功,反馈信息为:
PTY allocation request failed on channel 0
Hi csuherui! You’ve successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

4.上传本地仓库到远程仓库
$ git remote add origin git@github.com:csuherui/demo.git
git@github.com:csuherui/demo.git中只有csuherui/demo是需要改动的,是github用户名/仓库名
可以在github中找到你的demo仓库的ssh地址:

$ git push -u origin master
确认执行上传操作,正常反馈信息:
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 1.08 KiB | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
Branch master set up to track remote branch master from origin.
To github.com:csuherui/demo.git
* [new branch] master -> master
在github上刷新,你会发现代码已经从本地仓库上去了

账号操作
git config –global user.name csuherui #用户名
git config –global user.email csuherui@sina.com #邮箱

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值