一、安装egit
打开Eclipse的Marketplace,在搜索框中输入egit即可,可以看到Eclipse4.4已经默认安装了egit,当然如果有新版本的egit发布的话,也可以在下图上点击Update更新即可,还可以点击Uninstall卸载该插件


二、配置git
在Eclipse中的项目上右击选择team->share project



配置好本地仓库的路径之后,如下图所示


点击Finish之后,项目上面可以看到很多的问号,这表示文件处于untracked状态,还没提交,这时候可以发现Eclipse的工作空间中,原来那个项目文件夹不见了,整个项目的文件都转移到了上面设置的仓库里面,在Github中新建一个仓库,名称无所谓,可以与本地项目相同也可以不同,之后在Eclipse中的项目右击,选择Team->commit,



当全选之后,commit按钮就会处于可用状态,点击“commit”即可提交代码到本地本地仓库,注意并没有提交到github上的远程仓库,这时候项目上的问号图标会消失,变成小圆桶的形状。
三、配置Eclipse的SSH
window->preference->general->network connection->SSH2->Key Management->generate RSA Key... ->apply->save private key...,然后将id_rsa.pub的内容添加到github上(Github的Settings有SSH keys->Add SSH Key->将id_rsa.pub内容填在key中,title任意)!注意在配置完成之后要重启Eclipse。
四、Push
这个时候项目右击->Team->remote->push,这时候会出现如下界面,到github上,打开你新建的仓库,复制HTTPS地址,然后填到URI中即可,User就填你的Github用户名,Password是你的密码







点击next之后,会出现


在ref中选择master,然后点击后面的Add按钮,再点击next即可,这时候会出现confirm界面,点击Finish按钮,该项目就会被推送到Github上的远程仓库,顺利的话,很快就完了。



这个时候如果遇到rejected界面,说明还没配置完,如果你点team->remote->push,无论怎么配都是不会成功的,no fast farward之类的,意思是应该先从github上pull一下,然后再push。当你pull时,又会马上提示各种没配置好。这时可以按如下操作:点window->preference->team->git->configuration->Repository Settings,Repository选择建立的本地仓库,然后点右边的open



将打开的config文件内容修改为
[core] symlinks = false repositoryformatversion = 0 filemode = false logallrefupdates = true bare = false ignorecase = true hideDotFiles = dotGitOnly [remote "origin"] url = git@github.com:shijiebei2009/DocumentMatching.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [user] name = shijiebei2009 email = 291699763@qq.com |
这里面的url地址是Github上的SSH地址。
五、先Pull一下再Push
然后重新push就可以成功咯!

