fenghzy 发表于 2018-9-16 13:31:03

Linux下使用git命令及github项目

  Linux下使用git命令及github项目
  说明:于2017年8月26日测试ok(金工)
  在linux下搭建git环境
  1、注册Github账号,网站:https://github.com
  2、Linux创建SSH密钥:
  方法一:ssh-keygen##一直默认就可以了
  方法二:ssh-keygen -t rsa -C "12700696@qq.com" //生成密钥,邮箱同上
  cat~/.ssh/id_rsa.pub //提交密钥,复制里面的密钥
  方法三:非交互式生成密钥:ssh-keygen-t rsa -N '' -f~/.ssh/id_rsa -C "12700696@qq.com"
  3、将公钥加入到Github账户信息Account Settings->SSH Key
  方法:登录到github网页中登陆自己的账号,然后再account setting中,找到SSH KEY讲复制的密钥加入(需要再次输入github的密码)
  4、测试验证是否成功。
  ssh -T git@github.com   提示successfully说明成功
  Hi someone! You've successfully authenticated, but GitHub does not provide shell access.
  同步github到本地
  1、复制项目到本地:
  git clone git@github.com:rshare/docker-installer.git   ##以SSH方式克隆到本地,可以读写
  git clone https://github.com/rshare/docker-installer.git ##以https方式克隆到本地,可以读写
  git同步的其他命令:
  git clone git://github.com:xxxx/test.git ##以gitreadonly方式克隆到本地,只可以读
  git clone git@github.com:xxx/test.git##以SSH方式克隆到本地,可以读写
  git clone https://github.com/xxx/test.git ##以https方式克隆到本地,可以读写
  git fetch git@github.com:xxx/xxx.git##获取到本地但不合并
  git pull git@github.com:xxx/xxx.git ##获取并合并内容到本地
  本地提交项目到github
  1、本地配置
  git config --global user.name 'onovps'   #设置用户名标识
  git config --global user.email 'onovps@onovps.com' #全局联系方式,可选
  git config --list    #查看git环境设置
  2、新建Git项目并提交到Github。
  mkdir testdir && cd testdir
  touch README.md
  git init #初始化一个本地库
  git add README.md #添加文件到本地仓库
  git rm README.md #本地倒库内删除
  git commit -m "first commit" #提交到本地库并备注,此时变更仍在本地。
  git commit -a##自动更新变化的文件,a可以理解为auto
  git remote add xx git@github.com:rshare/docker.git#增加一个远程服务器的别名。
  git remote rm xx   ##删除远程版本库的别名
  git push -u remotename master #将本地文件提交到Github的remoname版本库中。此时才更新了本地变更到github服务上。
  分支版本操作
  1、创建和合并分支
  git branch #显示当前分支是master
  git branch new-feature#创建分支
  git checkout new-feature#切换到新分支
  viindex.php
  git addindex.php
  git commit -a -m "added initial version of page cache"
  git push origin new-feature##把分支提交到远程服务器,只是把分支结构和内容提交到远程,并没有发生和主干的合并行为。
  2、如果new-feature分支成熟了,觉得有必要合并进master
  git checkout master#切换到新主干
  git merge new-feature##把分支合并到主干
  git branch #显示当前分支是master
  git push#此时主干中也合并了new-feature的代码
  --------------------------------------------
  实例:rshare个人github同步数据实战。
  第1步,登录github:
  1、注册Github账号,网站:https://github.com   我的账号:rshare密码:pass000
  2、Linux创建SSH密钥:
  方法一:非交互式生成密钥:ssh-keygen-t rsa -N '' -f~/.ssh/id_rsa -C "12700696@qq.com"
  cat~/.ssh/id_rsa.pub //提交密钥,复制里面的密钥(第3步要粘贴)
  说明:ssh-keygen是ssh密钥生成器,-t指定算法为rsa,-N指定密码为空,-f指定私钥位置,-C指定注释信息(不指定则为主机名)。
  3、将公钥加入到Github账户信息Account Settings->SSH Key
  方法:登录到github网页中登陆自己的账号,然后再account setting中,找到SSH KEY讲复制的密钥加入(需要再次输入github的密码)
  4、测试验证是否成功。
  ssh -T git@github.com   提示successfully说明成功
  Hi someone! You've successfully authenticated, but GitHub does not provide shell access.
  ##同步github到本地
  1、复制项目到本地:
  mkdir/test
  cd/test
  git clone git@github.com:rshare/mydocker.git   ##以SSH方式克隆到本地,可以读写
  git clone https://github.com/rshare/docker-installer.git ##以https方式克隆到本地,可以读写
  ls查看文件列表
  2、创建新文件,并上传到github中。
  cd/test/mydocker
  ls -a
  gitremote
  cp-v/etc/{hosts,group,passwd}./
  gitaddhostsgrouppasswd
  gitstatus
  gitcommit-m'3files'
  gitpush-uoriginmaster
  验证:在github个人网站的mydocker仓库中查看是否多了三个文件(hosts,group,passwd)。
  git其他命令:
  git branch   #查看分支(即目录结构)
  3、删除远程仓库中的文件。
  cd/test/mydocker
  ls-a
  git rm --cachedhostsgrouppasswd    #删除缓存数据,并不删除本地文件
  gitstatus
  git commit -m "hehe"
  git push origin
  验证:在github个人网站的mydocker仓库中查看是否少了三个文件(hosts,group,passwd)。

  ====网络Dockerhub的使用=============
  flyer520对docker镜像下载和上传实例:
  第1步,注册docker-hub账号。在https://hub.docker.com/网站注册。
  注:我的账号是flyer520,邮箱12700696@qq.com
  第2步,linux登录docker测试。
  我的账号:docker login --username=flyer520--email=12700696@qq.com(登录OK)
  查看登录信息:cat~/.docker/config.json
  第3步,下载docker镜像。
  dockerpull busybox
  dockerpull nginx
  dockerimages
  第4步,修改标签(重设标签)。
  测试1:修改nginx标签,并push上传到flyer520的docker-hub中。
  dockertagnginxflyer520/nginx
  dockerpush flyer520/nginx
  测试2:修改busybox标签,并push上传到flyer520的docker-hub中。
  dockertag   busyboxflyer520/busybox
  dockerpush flyer520/busybox
  验证:登录到docker-hub,查看是否多了nginx镜像。

  ##搭建内部git仓库服务器

  待续....
  到此,本实验操作完毕。

页: [1]
查看完整版本: Linux下使用git命令及github项目