背景
在本地尝试Jenkins跑TestNG接口测试时,需要多次调试,就将本地代码上传到github仓库来配合调试。
1.在eclipse中安装EGit插件
打开Eclipse,点击Help选择Install New Software…,写好Name和Location,链接地址:http://download.eclipse.org/egit/updates,只需选择安装Eclipse Git Team Provider即可,安装完毕后重启Eclipse。


2.在eclipse中配置公钥并同步到github
1)配置git账号信息
点击Window——>Preferences——>Team——>Git——>Configuration,在User Settings栏目点击Enter Entry,添加user.name *******************和user.email *************,如下所示:


2)点击Window——>Preferences——>Network Connection——>SSH2
——>key management,点击Generate RSA key,会在下面的对话框中生成一串key

登录Github,进入setting——>SSH and GPG keys,点击New SSH Key,粘贴刚才生成的key并设置名称


3.项目配置git
1)配置本地仓库
项目名称右击,选Team——>Share Project…,选择Git。勾选Use or create repository in parent folder of project代表会将项目根目录当Git的本地仓库,之后出现如下面板。点击Create Repository,再点击Finish,到此为止本地仓库已经建好。
在平常修改代码之后,右键项目点击Team——>Commit就可以将更新的代码Commit到本地仓库上

2)文件加index
项目名称右击,选Team——>add to index
4.配置远程仓库
这时候,你就创建好了一个git工程,右击工程,选择Team,你可以像svn一样进行commit,synchronize等操作,但是,remote操作中,push是灰色的,表示还不能将代码推送到github仓库上去。
1)Git Repository
点击windows->show view->others,选择Git Repository

选择remote,右击create remote

选择config push,点击change

URI输入之前在github上拷贝的地址,下面的内容会自动填上。你只需要再填上github上的用户名和密码即可。finish,save。

2)commit
现将代码提交到本地,Team->commit ,输入提交描述,勾选掉不想上传的文件,点击commit

3)push
Team ->remote->push

push成功,GitHub上显示出上传的文件

网友评论