1. 程式人生 > >“Nothing to push” error in Android studio with Git

“Nothing to push” error in Android studio with Git

在Android studio下使用git

參考:http://www.tuicool.com/articles/V7j6Zfq

1.準備安裝 git :

sudo apt-get install git-core

參考:https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-12-04

在Android studio中設定git外掛:File->Setting->Version Control->Git, 然後可以點選Test測試一下,如下圖:那麼你就設定成功了。

2.初始化git專案(git init)

操作如下:VCS->Enable Control Integration->Select "Git".

3.為git新增remote

在這一步中,studio沒有為我們提供視覺化的GUI,在terminal下將目錄切換到專案的目錄,然後輸入git新增remote的命令,例如:git remote add origin "https://github.com/xxx/xxx.git".

4.將程式碼新增到VCS(git add)

選中要提交的檔案->VCS->Git->Add

5.提交變化(git commit)

VCS->Commit Changes在提交的時候可以選擇Commit and Push,就可以直接push到伺服器。

在第一次提交時可能會出現 “Nothing to push” 的問題

參考:http://stackoverflow.com/questions/15913669/nothing-to-push-error-in-intellij-with-git

因為第一次提交,repository為空,沒有master,你需要 在push介面中最下方的checkbox上挑勾,選擇"Push current branch to alternative branch"

並且填寫為master即可,這樣就能建立master,以後push就不需要checkbox了,除非新增新的分支。

When you push to an empty repository you must set on checkbox "Push current branch to alternative branch" and choose master as that alternative.It's because master is not created yet (repo is really empty). But doing this way you can pretend to initialize the repository.

While that checkbox is off and repository is empty, IDEA can't push, because its interface must be safe and he will not just create new brach if the one in which you pushed last accidentally disappeared (or just not exist). You must force that "branch creation"