Git是一个功能强大的分布式版本控制系统,最初用来作Linux内核代码管理的。

第一次接触到github是关于一个报道:在2013年1月15日晚间,全球最大的社交编程及代码托管网站GitHub突然疑似遭遇DDOS攻击,访问大幅放缓,该网站管理员经过日志查询,发现是来自12306的抢票插件用户洪水般的访问导致GitHub出现问题。

进入正题,github的第一次使用大概分以下步骤:
(环境:readhat 5, 提前装好git。若没有安装,用“yum install git-core”命令安装,解决各种依赖问题,很方便。)

1. 申请github账户,并创建repository

2. 本地生成密钥对

3. 设置github上的公钥

4. 创建本地项目

  • 申请github账户,并创建repository

在https://github.com上申请github账户,我的账户名是toughhou,并创建了名为etl的repository。

  • 本地生成密钥对

Git 服务器通常使用 SSH 公钥来进行授权。SSH 公钥默认储存在账户的主目录下的 ~/.ssh 目录。系统中的每个用户都必须提供一个公钥用于授权,没有的话就要生成一个。我没有,这里创建一个。步骤如下:

[root@ora11g ~]# mkdir .ssh
[root@ora11g ~]# cd .ssh/

//用ssh-keygen命令来生成密钥对,passphrase我们输入或不输入都行。

[root@ora11g .ssh]# ssh-keygen -t rsa -C "toughhou@126.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
03:73:b8:13:4c:cb:63:d0:c3:0b:5d:03:7d:0f:7e:18 toughhou@126.com

[root@ora11g .ssh]# ll
total 8
-rw------- 1 root root 1675 May  5 23:25 id_rsa
-rw-r--r-- 1 root root  398 May  5 23:25 id_rsa.pub

id_rsa.pub就是公钥文件,id_rsa就是密钥。

  • 设置github上的公钥

步骤如下:
    a. 登陆github后 -> "Account Setting" -> "SSH Keys"
    b. "Add SSH Key"
    c. Title随便填写一个,Key那里我们把把id_rsa.pub里的内容拷贝进去。

//好了之后用以下命令测试,若显示信息如下,则说明设置成功了。

[root@ora11g etl]# ssh -T git@github.com
Hi toughhou! You've successfully authenticated, but GitHub does not provide shell access.

  • 创建本地项目

[root@ora11g ~]# mkdir etl
[root@ora11g ~]# cd etl/

//git初始化

[root@ora11g etl]# git init
Initialized empty Git repository in /root/etl/.git/

[root@ora11g etl]# touch readme.txt

[root@ora11g etl]# git add readme.txt

//使用git协议定义远程服务器别名origin

[root@ora11g etl]# git remote add origin git@github.com:toughhou/etl.git

此处需要注意:
    git默认使用https协议,每次pull或push都要输入密码,比较麻烦。而且因为操作系统版本及一些库文件不全,设置起来很繁琐。
    我们这里使用git协议,然后使用ssh密钥。这样可以省去每次都输密码。

用https协议方式定义远程服务器别名:git remote add origin https://github.com/toughhou/etl.git

//查看你当前的remote url

[root@ora11g etl]# git remote -v
origin  https://github.com/toughhou/etl.git (fetch)
origin  https://github.com/toughhou/etl.git (push)

//commit

[root@ora11g etl]# git commit -m "First commit!!"
git commit -m "First commitgit remote -v"
[master (root-commit) 4bd96e9] First commitgit remote -v
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 readme.txt

//push

[root@ora11g etl]# git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 215 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:toughhou/etl.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

push完成之后,登陆github (https://github.com/toughhou/etl)查看,文件已经同步上去。

测试完成。

//文中提到的如果用的是https协议的话,效果如下。push时需要输入密码。

[root@ora11g etl]# git remote add origin9 https://github.com/toughhou/etl.git

[root@ora11g etl]# git push -u origin9 master
Username for 'https://github.com': toughhou
Password for 'https://toughhou@github.com': 
Branch master set up to track remote branch master from origin9.
Everything up-to-date

用https协议的话,可能会碰到一些问题。这里把我碰到的问题及解决方式记录如下:

[root@ora11g etl]# git push -u origin master
error: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing https://github.com/toughhou/etl.git/info/refs?service=git-receive-pack
fatal: HTTP request failed

[root@ora11g etl]# curl http://curl.haxx.se/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  244k  100  244k    0     0   7785      0  0:00:32  0:00:32 --:--:--  2690

[root@ora11g etl]# git push -u origin master

(gnome-ssh-askpass:14850): Gtk-WARNING **: cannot open display:  
error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass'
Username for 'https://github.com': toughhou

(gnome-ssh-askpass:14856): Gtk-WARNING **: cannot open display:  
error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass'
Password for 'https://toughhou@github.com': 
Branch master set up to track remote branch master from origin.
Everything up-to-date

[root@ora11g etl]# echo 'unset SSH_ASKPASS' >> ~/.bashrc && source ~/.bashrc

[root@ora11g etl]# git push -u origin master                                
Username for 'https://github.com': toughhou
Password for 'https://toughhou@github.com': 
Branch master set up to track remote branch master from origin.
Everything up-to-date


Linux环境下GIT初次使用的更多相关文章

  1. linux环境下git的安装配置

    1.查看git的最新版本: 查看最新版git:访问https://www.kernel.org/pub/software/scm/git/或者https://github.com/git/git/re ...

  2. Linux 环境下 Git 安装与基本配置

    索引: 目录索引 参看代码 GitHub: git.txt 一.Linux (DeepinOS) 环境 1.安装 sudo apt-get update sudo apt-get install gi ...

  3. linux 环境下git 命令小结

    转载自:http://blog.chinaunix.net/uid-28241959-id-3880025.html 本地建立仓库 先创建个文件夹,仓库的地点: mkdir cangkumkdir C ...

  4. linux 环境下git的安装与配置

    git是一个分布式的版本控制工具 1.安装git相关的依赖 yum install curl-devel expat-devel gettext-devel openssl-devel zlib-de ...

  5. linux环境下安装git(采用github下载git源码编译)

    [目的]:linux环境下 安装配置git成功 [准备条件]linux系统,git包 1.先行下载git包 -- 从github上https://github.com/git/git/releases ...

  6. 基础--Redis在Linux环境下的安装

    1. 安装redis服务 1.1 检查安装依赖程序 yum install gcc-c++yum install -y tclyum install wget 1.1.1 下载redis安装包 (或者 ...

  7. IDEA环境下GIT操作浅析之一Idea下仓库初始化与文件提交涉及到的基本命令

    目标总括 idea 下通过命令操作文件提交,删除,与更新并推送到github 开源库基本操作idea 下通过命令实现分支的创建与合并操作 idea 下通过图形化方式实现idea 项目版本控制基本操作 ...

  8. Linux环境下Gitblit服务搭建及秘钥配置

    一.安装gitblit服务 1.下载地址 https://pan.baidu.com/s/1wQ3TEE_gw5xZvyFPZB9xFg 2.上传至linux服务器并解压缩 tar xvf gitbl ...

  9. Linux环境下第一次提交项目

    Linux环境下第一次提交项目: vi 日记 新增一个文件名为“日记”的文件 git status 工作区的状态 git add 日记 建立跟踪 git commit 提交变更 ----------- ...

随机推荐

  1. python连接字符串的方式

    发现Python连接字符串又是用的不顺手,影响速度 1.数字对字符进行拼接 s=""  #定义这个字符串,方便做连接 print type(s) for i in range(10 ...

  2. Unity之读取本地图片

    1.下载Opencv for unity. 2.把OpenCVForUnity下的StreamingAssets拖到Assets下. 3.点击Tools->opencv for unity-&g ...

  3. MVC datetime? & datetime 设置格式

    设置datetime的格式,直接有方法重载进行,即使数据为datetime?格式 设置起始时间在配置的时候添加设置 $('#closeTime').datetimepicker({ language: ...

  4. sass中出现的中文问题

    在这园子里看到了很多优秀的资源,自己也想写写东西,就突然想到了以前遇到写sass的时候出现中文乱码的解决方案.所有就自己又总结了一下.(以下测试步骤都是自己完成的!没有任何转载,如有错误,希望大家指正 ...

  5. html使用空格对齐文本(   )

    字符以及HTML实体 描述以及说明   这是我们使用最多的空格,也就是按下space键产生的空格.在HTML中,如果你用空格键产生此空格,空格是不会累加的(只算1个).要使用html实体表示才可累加. ...

  6. SQL事务隔离级别

    数据库是要被广大客户所共享访问的,那么在数据库操作过程中很可能出现以下几种不确定情况. 更新丢失(Lost update) 两个事务都同时更新一行数据,但是第二个事务却中途失败退出,导致对数据的两个修 ...

  7. RedHat Install

    1. 插入光盘1并从光盘启动加载镜像文件 2. 回车后进入安装流程 3. 选择语言 4. 选择键盘布局 5. 鼠标配置 6. 选择安装类型 7. 选择分区类型 8. 添加一个boot分区 9. 新建一 ...

  8. ASP.NET jquery ajax传递参数

    第一种:GET传递 前台 ajax   GET 传递 :即在请求的地址后面加上参数,URL地址长度有显示,安全性低 后台接收:Request.QueryString[“参数名字”]! 例如: func ...

  9. dropdownlist分页

    <div class="new-paging" id=""> <div class="new-tbl-type"> ...

  10. Collection 和 Collections的区别。

    Collection 和 Collections的区别. Collections是个java.util下的类,它包含有各种有关集合操作的静态方法. Collection是个java.util下的接口, ...