[关闭]
@K1999 2017-02-07T01:58:14.000000Z 字数 1639 阅读 1674

Windows下github的使用

管理工具

1. 下载git客户端

这里用msysgit 下载地址

2. 创建项目

登录github,点击New repository
Repository name:Hello-World

  1. $ git config --global user.name "YourName"
  2. $ git config --global user.email "YourE-mail"
  3. $ git config --lis
  4. $ mkdir ~/Hello-World #在本地建对应的repository
  5. $ cd ~/Hello-World/
  6. $ git init
  7. #Initialized empty Git repository in C:/Users/Eaton-PC/Hello-World/.git/
  8. $ touch README.md
  9. $ git add README.md
  10. $ git commit -m 'first commit' #提交记录说明
  11. $ git remote add origin https://github.com/YourName/Hello-World.git
  12. $ git push origin master

3. 创建SSH KEY

3.1 检查原有密钥

  1. $ cd ~/. ssh #检查本机的ssh密钥

如果有此文件夹,说明不是第一次使用,执行下面的操作,清理原有ssh密钥。

  1. $ mkdir key_backup
  2. $ cp *_rsa* key_backup
  3. $ rm *_rsa*

3.2 生成新的密钥

  1. $ ssh-keygen t rsa C "YourName@xxx.com"

这里的邮箱地址YourName@xxx.com是自己的邮箱地址,回车之后会让你输入保存密钥的文件名,这里输入id_rsa。最后会得到id_rsa和id_rsa.pub两个文件,前者是私钥,后者是公钥。

3.3 添加密钥

添加私钥到ssh:

  1. $ ssh-add id_rsa

如果报错:Could not open a connection to your authentication agent.
先执行一下:

  1. $ ssh-agent bash

再执行 ssh-add id_rsa。
将公钥添加到github中,Personal settings中选择SSH keys,在New SSH Key中Title填写本机的名字,Key是把公钥文件的内容贴进来。

3.4 测试一下

  1. $ ssh git@github.com

如果出现下面内容,说明连接成功了

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

4 开始使用

4.1 获取源码

  1. $ git clone https://github.com/Eaton18/Hello-World.git

后面的链接是项目在github中的地址。

4.2 获取版本更新

假如本地已经存在了这个项目,而仓库中又有更新,获取更新:

  1. $ git fetch origin //取得远程更新,这里可以看做是准备要取了
  2. $ git merge origin/master //把更新的内容合并到本地分支/master

4.3 提交本地修改的版本

本地编辑了项目之后,将当前版本上传到仓库中

  1. $ git add *
  2. $ git status //可以看到我们对哪些文件做了修改
  3. $ git commit -m 'update project' #提交记录说明
  4. $ git push origin master

4.4 删除仓库中的文件

  1. $ git status
  2. $ git rm hehe/hello.txt
  3. $ git commit -m 'del txt'
  4. $ git push origin master
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注