GitHub使用教程

1 注册 GitHub 账户

要想使用github第一步当然是注册github账号了(www.github.com)。

2 安装客户端 msysgit

github是服务端,要想在自己电脑上使用git我们还需要一个git客户端,我这里选用msysgit,是基于命令行的。装完msysgit后,右键鼠标会多出一些选项来。

3 建立本地 git 仓库

在D盘下创建目录git_repository(后续的项目都可以集中放在git_repository中),可以通过在git bash中执行以下命令完成:

$ cd /d
$ mkdir git_repository

4 SSH key

为了把本地的仓库传到github,需要配置ssh key。

(1)生成SSH key

$ ssh-keygen -t rsa -C "your_email@example.com"  //之后一直回车,直到生成

注意:ssh-keygen中的邮箱请使用github注册用户时使用的邮箱。

(2)将新生成的 SSH key加入ssh-agent(可以省略此步骤)

$ ssh-agent -s   //输出:Agent pid 59566
$ ssh-add ~/.ssh/id_rsa

如果输出:

Could not open a connection to your authentication agent.

则先执行如下命令:

$ ssh-agent bash

再执行:

$ ssh-add ~/.ssh/id_rsa

(3)将SSH key 加入GitHub

$ clip < ~/.ssh/id_rsa.pub  //复制到剪切板

之后在 GitHub网站中Add SSH key

(4)验证是否成功加入SSH key

$ ssh -T git@github.com   //之后选yes

若成功,则输出:

Hi “你的用户名”! You've successfully authenticated, but GitHub does not provide shell access.

5 设置username和email

因为github每次commit都会记录他们。

$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"

设置后可以用下面命令查看:

$ git config –list

6 在 GitHub 中创建 Repository

(1)创建 GitHub中的仓库

New Repository,填好名称后Create,之后会出现一些仓库的配置信息,这也是一个git的简单教程,如下:

create a new repository on the command line

git init   //初始化
touch README.md
git add README.md //开始跟踪新文件或暂存已修改文件
git commit -m "first commit" //提交更新,并注释信息“first commit” ,注意提交的是暂存区的文件(即add过的文件)
git remote add origin https://github.com/account/demo.git //连接远程github项目
git push -u origin master //将本地项目更新到github项目上去

进入.git,打开config,这里会多出一个remote “origin”内容,这就是刚才添加的远程地址,也可以直接修改config来配置远程地址。

push an existing repository from the command line

git remote add origin https://github.com/account/demo.git
git push -u origin master

import code from another repository

You can initialize this repository with code from a Subversion, Mercurial, or TFS project.

(2)在本地创建一个相同项目

$ cd /d/git_repository
$ mkdir demo //创建一个项目demo
$ cd demo //打开这个项目

之后按照(1)中的 【create a new repository on the command line】步骤操作即可,具体如下。

$ git init
$ git add .//添加所有文件

此时会出错【warning: LF will be replaced by CRLF】.因为windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时出现提示,解决办法:

$ rm -rf .git  // 删除.git
$ git config --global core.autocrlf false //禁用自动转换
$ git init
$ git add .

忽略Warning: Your console font probably doesn't support Unicode. If you experience strange characters in the output, consider switching to a TrueType font such as Lucida Console!

$ git commit -m "first commit"
$ git remote add origin https://github.com/account/demo.git
$ git push -u origin master

(3)以后每次修改项目后提交github

$ git add .
$ git commit -m "commit msg"
$ git push -u origin master

【原】GitHub使用教程的更多相关文章

  1. Git和Github简单教程

    原文链接:Git和Github简单教程 网络上关于Git和GitHub的教程不少,但是这些教程有的命令太少不够用,有的命令太多,使得初期学习的时候需要额外花不少时间在一些当前用不到的命令上. 这篇文章 ...

  2. GitHub 使用教程图文详解(转)

    大纲: 一.前言 二.GitHub简介 三.注册GitHub账号 四.配置GitHub 五.使用GitHub 六.参与GitHub中其它开源项目 七.总结 注,GitHub官网:https://git ...

  3. github 基础教程推荐

    github现在很火的样子 我在一篇博客上看到说“如果你不知道什么是github,那你就不能说你是个coder,如果你现在看到这篇博客,那么你已经是个coder了”. 我对github一直很好奇,可是 ...

  4. 【软件使用】GitHub使用教程for VS2012

    一直以来都想使用Git来管理自己平时积累的小代码,就是除了工作之外的代码了.有时候自己搞个小代码,在公司写了,就要通过U盘或者网盘等等一系列工具进行Copy,然后回家才能继续在原来的基础上作业.Cop ...

  5. Git-it:一个学习Git和Github的教程(软件)

    Git-it https://github.com/jlord/git-it 2016-08-01 在FreeCodeCamp的引导下了解到的Git-it.OSC有收录. Git-it是一个指导使用G ...

  6. GitHub具体教程

    GitHub具体教程 Table of Contents 1 Git具体教程 1.1 Git简单介绍 1.1.1 Git是何方神圣? 1.1.2 重要的术语 1.1.3 索引 1.2 Git安装 1. ...

  7. GitHub详细教程

    GitHub详细教程 Table of Contents 1 Git详细教程 1.1 Git简介 1.1.1 Git是何方神圣? 1.1.2 重要的术语 1.1.3 索引 1.2 Git安装 1.3 ...

  8. GitHub 使用教程图文详解

    大纲: 一.前言 二.GitHub简介 三.注册GitHub账号 四.配置GitHub 五.使用GitHub 六.参与GitHub中其它开源项目 七.总结 注,GitHub官网:https://git ...

  9. Git和Github简单教程(收藏)

    原文链接:Git和Github简单教程 目录: 零.Git是什么 一.Git的主要功能:版本控制 二.概览 三.Git for Windows软件安装 四.本地Git的使用 五.Github与Git的 ...

随机推荐

  1. Linux-echo:打印彩色输出

    脚本可以使用转义序列在终端中生成彩色文本 文本颜色是由对应的色彩码来描述的.其中包括: 重置=0,黑色=30,红色=31,绿色=32, 黄色=33,蓝色=34,洋红=35,青色=36,白色=37. 要 ...

  2. foreach中的&用法

    原地址:https://blog.csdn.net/qq_38287952/article/details/79468321 例如,给数组添加一个新的元素. 这里的需求是统计商品收入,就可以用到&am ...

  3. Python与用户的交互

    目录 Python与用户的交互 为什么交互 如何交互 Python2 中的交互 Python与用户的交互 为什么交互 让我们来回顾计算机的发明有何意义,计算机的发明是为了奴役计算机,解放劳动力.假设我 ...

  4. spark on yarn UI界面详解

    参考: spark on yarn图形化任务监控利器:History-server帮你理解spark的任务执行过程 spark内存分配原理 yarn运行原理详解 task,executor,core等 ...

  5. 树莓派驱动开发 helloworld

    编写Makefile ifneq ($(KERNELRELEASE),) obj-m := MiniX.o else KDIR := /home/hi/pi/kernel/linux/ all: ma ...

  6. asp.net 6.aspx页面

    1.aspx页面的头部 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Us ...

  7. Linux Too many open files

    Linux Too many open files 查看系统资源限制信息: sudo -s -u root -H id sudo -s lsof | awk '{ print $2 " &q ...

  8. golang(8):channel读写 & goroutine 通信

    goroutine 1.进程和线程 A. 进程是程序在操作系统中的一次执行过程,系统进行资源分配和调度的一个独立单位 B. 线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独 ...

  9. SpringBoot整合Mybatis关于分页查询的方法

    最近公司在用到SpringBoot整合Mybatis时当web端页面数据增多时需要使用分页查询以方便来展示数据.本人对分页查询进行了一些步骤的总结,希望能够帮助到有需要的博友.如有更好的方式,也希望评 ...

  10. CentOS 7.6 64位安装docker并设置开机启动

    步骤如下 安装docker.docker-compose yum -y install docker-io docker-compose 启动docker service docker start 设 ...