Intellij IDEA 提交代码到远程GitHub仓库

转载地址:http://www.cnblogs.com/exmyth/p/6133289.html 

1.文章参考自http://my.oschina.net/lujianing/blog/180728

2.设置相关绑定 
Settings——Version Control——Git——Path to Git executable——选择你的安装目录Intellij IDEA 提交代码到远程GitHub仓库

Settings ——Version Control——GitHub这边Host:github.com Login:账号 Password:密码 
Intellij IDEA 提交代码到远程GitHub仓库

3.项目的本地git提交 
intellij内部集成了git版本控制 所以在本地可以直接进行使用

3.1创建本地仓库 
Intellij IDEA 提交代码到远程GitHub仓库 
Intellij IDEA 提交代码到远程GitHub仓库

选择工程的目录,点击OK后,IDEA会为该工程建立git仓库,可以到该工程的目录下,看到.git文件夹,表明建立git仓库成功。但是同时IDEA会提示:The directory E:\Git\coding\learnTest is under Git, but is not registered in the Settings.如下所示。 
Intellij IDEA 提交代码到远程GitHub仓库

只需要点击Configure。然后选择右上角的绿色+号 
Intellij IDEA 提交代码到远程GitHub仓库

就可以将仓库在idea里进行注册 
Intellij IDEA 提交代码到远程GitHub仓库

3.2提交代码到本地git 
右键项目或者文件 Git——Add——Commit (先add 然后再提交) 

4.配置远程提交 
4.1 github上创建仓库
 
Intellij IDEA 提交代码到远程GitHub仓库 
4.2 Git Shell中配置远程仓库 
Intellij IDEA 提交代码到远程GitHub仓库 
如果我们第一次什么都没有做,就想提交到远程仓库的话。会出现如下的错误 
Intellij IDEA 提交代码到远程GitHub仓库 
这个时候我们需要建立一条分支,并且做了一次commit。 
Intellij IDEA 提交代码到远程GitHub仓库 
Intellij IDEA 提交代码到远程GitHub仓库 
问题解决方法参考自*:http://*.com/questions/12452042/git-error-src-refspec-master-does-not-match-any-error-failed-to-push-some-refs 
Intellij IDEA 提交代码到远程GitHub仓库

这时候再一次提交到远程仓库,可能会出现如下问题。 
Intellij IDEA 提交代码到远程GitHub仓库

好像问题是因为github建立的工程下有README文件,而我们建立的工程没有,此时我们可以用git push -f origin master,强制提交,覆盖github上的工程。但是只能第一次用,如果一直这样子提交,会覆盖github上的内容。 
Intellij IDEA 提交代码到远程GitHub仓库 
问题解决方法参考自*:http://*.com/questions/20939648/issue-pushing-new-code-in-github 
Intellij IDEA 提交代码到远程GitHub仓库