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

最新文章

  1. Apache安装问题:configure: error: APR not found . Please read the documentation
  2. 异常检测算法--Isolation Forest
  3. [TimusOJ1057]Amount of Degrees
  4. .net的五层架构
  5. 字符串去空格 java , js和Jquery 方法
  6. 分享一个Mongodb PHP封装类
  7. js部分---流程语句的基本形式;
  8. 《我是一只it小小鸟》
  9. jquery创建动态的div
  10. 异常捕获拒绝闪退 让应用从容的崩溃UncaughtExceptionHandler
  11. .net core 持续构建简易教程
  12. Effective Java 第三版——9. 使用try-with-resources语句替代try-finally语句
  13. 与eslint有关的规范
  14. Ubuntu 下生成 python 环境安装文件 requirements.txt
  15. unity UI如何开启(显示)或者关闭(隐藏)Panel界面最好?
  16. 2018-08-11 中文代码示例之Spring Boot 2.0.3问好
  17. Selenium环境搭建---C#
  18. spring4.0.0 源码导入eclipse(sts)
  19. WAS6.1连接SQL Server2008数据库连接池配置
  20. java基础-Map集合

热门文章

  1. Nginx整合Tomcat
  2. css动画(transition/transform/animation)
  3. 使用tqdm实现下载文件进度条
  4. python + Pyglet ---播放视频
  5. Codeforces Round #406 (Div. 2) A MONSTER
  6. node 环境安装
  7. 服务端相关知识学习(二)之Zookeeper可以干什么
  8. 带她来看Frozen 2
  9. O062、NFS Volume Provider(Part I)
  10. 抓包工具之tcpdump