9404803 发表于 2018-1-14 15:26:16

在linux中安装git,并将代码发布到github

  楼主Git小白,今天刚刚学习了git,虽然在工作中也许用不到,但是在学习的时候肯定会用到的,毕竟一个程序员首先就要整理自己的知识点,将美丽的代码分享与大家。
  楼主是将Git安装在阿里云的centos7(新手半年9元,虽然配置不高,但是足够我们使用,此处不是广告,好东西大家分享。)上。
  创建git文件夹,在此处安装git:
  

mkdir git  

  进入git文件夹:
  

cd git  

  安装git,因为centos安装的命令行和linux操作系统不一样,所以在这里贴出来。在其中要输入y,确定下载安装包。:
  

centos:yum install git  

  
linux:sudo apt
-get install git  

https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724002457511-600998202.png
  安装结束。在这个文件夹会有一些隐藏文件。大家也可以查看下自己安装的版本
  

ll -a  git --version
  

https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724003221136-106413879.png
  执行git init 命令,会生成.git文件夹,创建linux的库
  

git init  

  在linux上安装完git,咱也应该去github注册帐号了。github网址:https://github.com/
  相信注册一个帐号对大家没什么问题的把。在这里不添加教程。实在需要帮助请留言。
  咱已经在linux创建好了一个仓库,接下来只在github创建一个仓库将这两个仓库关联就可以了。
  在github首页右下角,点击New repository。
https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724003652011-342861053.png
https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724003902245-1865604466.png
  接下来咱就是要把git和github的库关联起来。要实现他们的远程同步就是需要用到SSH Key,github拿到了你的公钥就会知道内容是你推送的。
  切换好.ssh目录,执行:ssh-keygen -t rsa -C '你github的帐号' ,执行完连续按回车键继续。
  

cd /root/.ssh/  

ssh-keygen -t rsa -C '88888888@qq.com'    # '88888888@qq.com' 为 你github的帐号 
  

https://images2017.cnblogs.com/blog/1066644/201708/1066644-20170802160303865-1713833452.png
  在这个目录下的id_rsa.pub里面的内容就是我们要的SSH Key,打开id_rsa.pub,将里面所有的内容复制到githubsetting里面的SSH and GPG keys的SSH 的 key文本库,title自拟。
  当然你不仅可以在github根据界面查看是否成功,也可以在git测试是否成功,失败百度下是什么原因。
  

vim>ssh -T git@github.com        #测试是否连接成功
  

https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724005937417-176860848.png
https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724010235867-1751636865.png
https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724010223992-910191435.png
https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724010347008-1912067378.png
https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724011522633-1708880054.png
https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724011540305-1289741606.png
  接下来咱将目录切换到咱的git的仓库中。新建一个文件,在里面写上 I am leaning git.
https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724010920524-971308048.png
  接下来:添加test.txt到git并提交
  

git add test.txt  
git commit
-m test.txt   

https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724012944617-1729543674.png
  linux的仓库也要去关联github的仓库。第二次使用就不用这行命令,以为已经关联了
  

git remote add origin git@github.com:BeautifulMeet/gitDemo.git  #这个就是你github的地址 git@github.com:BeautifulMeet/gitDemo.git         替换成你的
  

  最后推送到github
  

git push origin master  

https://images2015.cnblogs.com/blog/1066644/201707/1066644-20170724013505055-275550003.png
页: [1]
查看完整版本: 在linux中安装git,并将代码发布到github