如何使用github?

来源:互联网 发布:mac定制双用粉底液53c1 编辑:程序博客网 时间:2024/05/17 09:16

    作为在IT界被广泛使用的公共代码平台,github已经成为IT从业人员必需熟练掌握的软件工具。本文是作者一个学习笔记。以供读者参考使用。Learn Git Baching

    所谓软件开发(代码)的版本控制(软件),是指在软件开发过程中,按照提交到服务器的时间顺序来存储代码的工具(软件)。因为是按照提交时间顺序来存储代码,所以,开发者可以方便比较指定的不同的提交时间(也称版本)的代码,从而方便追踪代码被修改的历史记录。常用的代码控制软件有:github,perforce。

    1. Github的网址:https://github.com/ 

    2. 在使用github之前,需要在上面注册。假设注册的用户名(username) 和密码(pwd)。

    3. 每个gitbhub账号的基本单位是repository(仓库)。对于客户端-服务器模式(也即我们通常使用的internet),即将被上传目录也叫local repository,上传的(在服务器端)的目录也叫remote repository。所以,我们的基本操作是如下两种:

    local repository (<- pull-)/(-push->) remote repositoy

    4. 使用github需要一个客户端。github是基于Linux开发的。在Linux操作系统中,可以直接下载安装github (sudo apt-get install git git-core)。在windows操作系统中,需要一个客户端。推荐使用msysgit(command-line interface)。

    5. 配置本地客户端。(我们假设msysgit已经正确安装)

      5.1 git config --global user.name "username"

      5.2 git config --gloabal user.email "email@server.com"

      5.3 ssh-keygen -t rsa -C "email@server.com"

      5.4 vim /home/linx/.ssh/id_rsa.pub  复制里面的密钥(或从文件C:\Users\wufan_000\.ssh\id_rsa.pub里面复制)到github/account setting/SSH KEY中。添加密钥,粘帖密钥,并保存。

    6. 检测连接成功:ssh git@github.com 

        返回信息(正常):

PTY allocation request failed on channel 0Hi plinx! You've successfully authenticated, but GitHub does not provide shell access.Connection to github.com closed.

    7. 上传流程

      7.1 创建即将提交文件夹 mkdir <folder_name>

      7.2 在文件夹内,设置当前目录为上传目录:git init

      7.3 生成readme文件(描述项目):touch README

      7.4 添加文件到提交列表:git add <file_name 1> <file_name 2>...

      7.5 提交修改声明:git commit -m "<The description of changes>"

        Note: 在提交文件前必须提交声明。

      7.6 确认提交列表:git status

      7.7 提交:git push origin master

      7.8 变更origin:变更origin之前需要先去掉已经设置的origin,git remote rm origin。之后git add origin git@github.com:user_name/repsitory_name.git。

    8. 下载代码

      8.1 git push origin master

    9. 分支

    10. 合并代码

    11. 错误信息及解决。

      11.1 “ERROR: Repository not found” - Repository名字不正确。

      11.2 “Permission denied...” - ssh code is not correctly copied to the repository.

0 0
原创粉丝点击