Linux中使用git工具提交文件至github(图文详解)

2017/11/0117:00:02 发表评论


摘要:工作期间我一直使用的是svn这种管理工具,随着开源软件的越来越流行,使用github的人也越来越多……OK,以上都是废话,本来是以一个使用github的入门选手记录的他的折腾过程。目的是快速搭建好github文件提交环境。


1、注册github账号

github官网:https://github.com/

如果连账号都不会注册的,那还建议你不要往下玩了吧


2、创建组织


创建一个组,这个组就相当于在一块地皮上建了一个大房子,这个房子里可以创建多个小房间,即仓库,billing Email那一栏必须要填写,你可以写上你自己的Email


如图,其它选项默认,最后点击"Create Organization",即可创建成功:


1509520752553321.png


3、创建仓库


接下来我们可以在第二步创建的组中,建立一个仓库,按图示从上到下操作:

1509521254121854.png


点击"Create repository"后就会跳转到如下页面,我们选择ssh连接github方式进行测试:


image.png


说明:实际测试中,我一开始采用的是https方式,在git push这一步,出现了报错,信息如下:

error: The requested URL returned error: 403 Forbidden while accessing

https://github.com/guozitest/software.git/info/refs

fatal: HTTP request failed

4、建立ssh密钥对


我们可以使用root账号,输入如下命令,创建密钥对:

ssh-keygen -C 'yourmail@server.com' -t rsa

连续按三次回车后,会在/root/.ssh目录下生成两个文件,id_rsa和id_rsa.pub,其中id_rsa.pub是我们需要将其内容拷贝到github账号中去的。


依次如下图示操作:

image.png

1509525523230520.png


点击"New SSH Key",填入我们上一步创建的密钥对,/root/.ssh/id_rsa.pub中内容

image.png


连接测试一下,输入命令:

ssh -v git@github.com
  #输出如下信息,有succeeded字样,说明连接测试成功:
  debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = C

5、克隆github分支至本地


二话不说就开干了,使用如下命令克隆刚刚创建好的仓库到本地:

mkdir /gitrepo
cd /gitrepo/
git clone git@github.com:guozitest/software.git

此时我们会看到在/gitrepo目录下生成了一个software文件,但里面什么东西都没有,

image.png


6、使用git工具创建、修改、提交文件


我们创建一个Reademe文件,在其中写上hello world,并提交:

image.png

我们发现,最后提交的时候直接使用git push会报错,说必须指定一个分支,由于我们是在master上提交的文件,所以加上-u origin master就OK了。


7、后续

github目前正在体验使用中,更多文章请关注果子哥博客

http://www.guoziweb.com/

  • 微信扫码赞助
  • weinxin
  • 支付宝赞助
  • weinxin

发表评论

您必须才能发表评论!