Github使用教程(一)

Github使用教程(一)

本文大量参考《Github入门与实践》一书。转载请注明出处。

全文分为六个部分,主要内容概述如下

  • 使用Github的前期准备
  • git的介绍与使用
  • github的主要功能
  • 尝试Pull Request
  • 使用GitHub的开发流程
  • 将github应用到企业

使用Github的前期准备

  • 设置SSH Key
    Github上连接已有仓库的认证,是通过使用SSH的公开秘钥
    运行下面的秘钥创建SSH Key

    $ ssh-keygen -t rsa -C "your_email@example.com"
    Generating public/private rsa key pair.
    Enter file in which to save the key
    (/Users/your_user_directory/.ssh/id_rsa): 按回车键
    Enter passphrase (empty for no passphrase): 输入密码
    Enter same passphrase again: 再次输入密码

    输入密码后会出现以下结果:
    接着添加公开秘钥
    $ cat ~/.ssh/id_rsa.pub
    ssh-rsa 公开密钥的内容 your_email@eaxample.com

    完成以上后邮箱会收到邮件
    然后接下来就可以用手中的私人秘钥与github进行认证和通信了。
    让我们来实际试一试。
    $ ssh -T git@github.com The authenticity of host 'github.com (207.97.227.239)' can't be established. RSA key fingerprint is fingerprint值 . Are you sure you want to continue connecting (yes/no)? 输入yes
    成功后
    Hi hirocastest! You've successfully authenticated, but GitHub does not provide shell access.

  • 创建工程
    因为不是新手教程前面的创建步骤就不详细介绍了。我们简要探讨
    最后两个添加文件Add.gitignore和Add a license。
    Add.gitignore主要作用是可忽视不需要版本控制的文件。
    Add a license选择要添加的许可协议文件。

  • clone已有仓库
    接下来我们将尝试在已有仓库中添加代码并加以公开
    $ git clone git@github.com:hirocastest/Hello-World.git
    Cloning into 'Hello-World'...
    remote: Counting objects: 3, done.
    remote: Total 3 (delta 0), reused 0 (delta 0)
    Receiving objects: 100% (3/3), done

    这里要求输入Gitgub上设置的公开密钥的密码。认证成功后,仓库便会被clone至仓库名后的目录中。将要提交的代码放入这个仓库,最后push到Github仓库中,代码便会公开。

  • 提交
    新建一个hello_word文件提交至仓库,这个文件就会进入版本控制之下,之后的管理都可以用git进行
    $ git add hello_world.php
    $ git commit -m "Add hello world script by php"
    [master d23b909] Add hello world script by php
    create mode 100644 hello_world.php

  • 进行push
    之后只要执行push就能更新GitHub上的仓库。
    $ git push
    Counting objects: 4, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 328 bytes, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To git@github.com:hirocastest/Hello-World.git 46ff713..d23b909 master -> master

    这样就完成了使用git上传代码到github上

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值