Git -- 使用GitHub

GitHub是个耳熟能详的东西,大大小小的开源软件多是在GitHub上建的git仓库,GitHub中只要你建立公共的仓库就是免费服务,当然私有的仓库就需要一些money了。
在GitHub上创建一个自己的仓库来存储代码是一件非常轻松且愉快的事情,只要有网络,你可以在任意时间和地点去同步你的代码,是不是很令人兴奋!
使用GitHub需要先注册一个帐户,关于注册不再赘述。
有了帐号之后,开始实验一下如何在本地与GitHub上的仓库进行同步。

1、还是ssh-key
在本地与GitHub进行交互,需要先添加本地机器的ssh-key到GitHub中,ssh-key通过”ssh-keygen“获取,然后保存到GitHub中的”帐户设置“->”SSH Keys”当中,这样本地才能够与GitHub中的仓库进行联系。

2、创建github仓库
这里写图片描述
在这里创建了一个名为”githubTest“的公共仓库,并自动创建了README.md文件。

仓库创建完成后,显示在”SSH“后方输入框中的就是用于clone的地址。

3、本地操作
在本地clone下来GitHub上刚创建的仓库,并新建一个文件推送到GitHub仓库中去:

[root@localhost ~]# git clone git@github.com:******/githubTest
正克隆到 'githubTest'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
接收对象中: 100% (3/3), done.
[root@localhost ~]# cd githubTest/
[root@localhost githubTest]# ls
README.md
[root@localhost githubTest]# 
[root@localhost githubTest]# cat README.md 
# githubTest[root@localhost githubTest]# 
[root@localhost githubTest]# echo "this second file" > 2th.txt
[root@localhost githubTest]# ls
2th.txt  README.md
[root@localhost githubTest]# git add 2th.txt 
[root@localhost githubTest]# git commit -m "add file -- 2th.txt"
[master 3f7dffd] add file -- 2th.txt
 1 file changed, 1 insertion(+)
 create mode 100644 2th.txt
[root@localhost githubTest]# git push origin master

完成推送后,再刷新GitHub上的仓库,就能够看到刚刚推送上去的新文件了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值