如何使用github?

本文介绍GitHub的基础使用方法,包括注册账号、配置客户端、上传与下载代码等步骤,帮助初学者快速上手GitHub。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    作为在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 0
Hi 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值