GitHub使用入门介绍

转载请标明出处:http://blog.csdn.net/u013254166/article/details/78615092
本文出自: rhino博客 

        本篇主要分三个步骤来介绍GitHub的使用,分别是搭建环境、上传和下载。

1. 配置环境

1.1 安装及配置环境变量

        首先需要一个GitHub账号,如果还没有就先去注册吧! https://github.com/
        然后需要下载git工具,默认安装就行  https://git-for-windows.github.io/
        安装完成后,需要配置环境变量,这样你就可以随处使用git命令了。

       

        拷贝git目录下cmd文件夹的路径到环境变量path就行。(计算机--属性--高级系统变量--环境变量--在系统变量找到path)

        

       然后我来检查一下,环境变量是否OK。命令行输入git --version出现下面现象即安装配置成功。

       

1.2 生成密钥对

        首先确认一下本机是否已经有一个公钥。
        $ cd ~/.ssh
        $ ls
        id_rsa   id_rsa.pub

        看一下有没有id_rsa和id_rsa.pub(或者是id_dsa和id_dsa.pub之类成对的文件),有 .pub 后缀的文件就是公钥,另一个文件则是密钥。
        假如没有这些文件,甚至连 .ssh 目录都没有,可以用 ssh-keygen 来创建。
        $ ssh-keygen -t rsa -C " [email protected]"
        Creates a new ssh key using the provided email # Generating public/private rsa key pair.
        Enter file in which to save the key (/home/you/.ssh/id_rsa):
        直接三个回车就行。

1.3 添加密钥到远程仓库(github)

        (1) 查看你生成的公钥:
        $ cat id_rsa.pub
        ssh-rsa                
        SFf2egbiwS860jWXs55xhSFfxxx...

        (2) 添加到GitHub
        登陆你的github帐户。点击你的头像,然后 Settings -> 左栏点击 SSH and GPG keys -> 点击 New SSH key,然后你复制上面的公钥内容,粘贴进“Key”文本域内。 title域,自己随便起个名字。点击Add SSH key。

        (3) 验证是否成功
        $ ssh -T [email protected]
        Hi rhinoSp! You've successfully authenticated, but GitHub does not provide shell access.

2. 上传

2.1 新建项目

         登陆进入首页,点击New repository。

        

        填写基本信息后,点击Create repository,下面是基本信息介绍。

        Repository name: 仓库名称

        Description: 仓库描述介绍(可选)

        Public, Private : 仓库权限(公开共享,私有或指定合作者)

        Initialize this repository with a README: 添加一个README.md

        gitignore: 不需要进行版本管理的仓库类型,对应生成文件.gitignore

        license: 证书类型,对应生成文件LICENSE
        
        
2.2 开始上传

        进入到本地工程目录,右键--Git Base Here,然后依次执行一下命令即可。
         git init
         git add .
         git remote add origin https://github.com/rhinoSp/Test.git (这里的url地址是你GitHub工程的的地址,进入工程点击Clone or download可以看到)
         git commit -m "first commit"

        git push origin master


        注:如果push出现以下错误

        ! [rejected] master -> master (fetch first)
        error: failed to push some refs to 'https://github.com/rhinoSp/Test.git'

        先执行 git pull --rebase origin master, 再执行 git push -u origin master 就可以了

3. 下载

        新建一个文件夹,进入文件夹,右键--Git Base Here,然后依次执行一下命令即可。
         git init
        git remote add origin https://github.com/rhinoSp/Test.git
        git pull origin master