一.安装git

  • CentOS

    yum install git

  • 安装成功后,检查是否安装成功

    git --version

  • 如果版本过低就是用源码编译安装

    • 安装依赖包
      yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
    • 下载git源码并解压缩
      wget https://codeload.github.com/git/git/zip/master
      unzip master
      cd git-master
    • 编译安装
      make prefix=/usr/local/git all
      make prefix=/usr/local/git install
      mv /usr/bin/git /usr/bin/git-bak && ln -s /usr/loca/git/bin/git /usr/bin/git
    • 再次使用git —version 查看git版本,确认是否升级成功

      二,设置git

  • 设置用户名和email
    git config --global user.name "Your Name"
    git config --global user.email "youremail@xx.com"

  • git配色
    git config --global color.status auto
    git config --global color.diff auto
    git config --global color.branch auto
    git config --global color.interactive auto

    三、为GitHub账号添加SSH Keys

  • 以公钥认证方式访问SSH协议的Git服务器时无需输入口令,而且更安全。

    • 创建SSH key,输入以下命令连续回车即可会自动在~/.ssh生成密钥
      ssh-keygen
    • 将idrsa.pub文件内的内容,粘帖到github帐号管理的添加SSH key界面
      _cd ~/.ssh/id_rsa.pub && cat id_rsa.pub_
    • _添加到GitHub
      登录github-> Accounting settings图标-> SSH key-> Add SSH key-> 填写SSH key的名称(可以起一个自己容易区分的),然后将拷贝的~/.ssh/id_rsa.pub文件内容粘帖-> add key”按钮添加
    • 测试,出现以下提示则表示成功
      ssh -T git@github.com
      (Hi leoiceo! You’ve successfully authenticated, but GitHub does not provide shell access.)

      四、为GitHub上的Repository提交修改

  • git clone已存在GitHub上的Repository
    git clone https://github.com/leoiceo/study_python

  • 修改一个文件然后提交

    1. vim README.md
    2. git add README.md # 添加一个文件
    3. git status
    4. git commit -m "test" # 注释
    5. git status
    6. git remote add origin https://github.com/leoiceo/study_python.git # 关键本地库和远程库

    ```

  • 将修改push到GitHub上
    git push -u origin master

  • 提交完成后,查看GitHub上的Repository,会发现内容修改成功。