今天想使用github托管一个开源的项目,由于github使用的版本控制软件是git,以前只用过svn,所以研究了一下关于git的使用,包括如何将代码上传到github.com,如何使用Eclipse的git插件EGit。

Mark一下备忘!

一、配置Git环境

1、上官网(http://git-scm.com/)下载最新版的git,并安装

2、双击Git Bash程序,进入命令窗口

3、配置ssh

ssh -T git@github.com 输出:

The authenticity of host 'github.com (207.97.227.239)' can't be established.
 RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
 Are you sure you want to continue connecting (yes/no)?

此处输入yes,回车,输出: Connection closed by 207.97.227.239

继续测试

$ ssh -T git@github.com
 Permission denied (publickey).

表示我们还没有权限,需要为本机生成公钥,执行命令: $ ssh-keygen

输出结果

Generating public/private rsa key pair.
 Enter file in which to save the key (/c/Users/liuzc/.ssh/id_rsa):
 Enter passphrase (empty for no passphrase):
 Enter same passphrase again:
 Your identification has been saved in /c/Users/liuzc/.ssh/id_rsa.
 Your public key has been saved in /c/Users/liuzc/.ssh/id_rsa.pub.
 The key fingerprint is:
 69:c5:5d:91:2b:6c:e7:ac:62:cf:xx:xx:xx:xx:xx:xx liuzc@LIUZC-PC

从上图中可以看到公钥已经生成,保存在c/Users/liuzc/.ssh/id_rsa.pub

用记事本打开id_rsa.pub,复制里面的内容

登录github.com,打开https://github.com/account/ssh,将复制过来的公钥添加到里面

 

继续测试

ssh -T git@github.com
 # 成功输出
 Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.

二、安装Eclipse EGit

在eclipse下选择Help–Eclipse Marketplace搜索egit,选择egit就可以了。不要同时选择jgit.

三、如何使用egit创建本地仓库

请参考官方文档:http://wiki.eclipse.org/EGit/User_Guide/Getting_Started

四、如何将Eclipse创建的项目上传到github.com

请参考官方文档:http://wiki.eclipse.org/EGit/User_Guide#Github_Tutorial 或者:http://www.vogella.com/articles/EGit/article.html 再或者:http://gemantic.iteye.com/blog/1211527