How to use GitHub with Android Studio
This article will explain how to use GitHub withAndroidStudio.
Firstly, let’s login togithub.comand create a new repository. From the top right corner of the screen, click the+sign and selectNew repository.
Now complete the form to create a new repository calledtestproject. Leave theInitialize this repository with a READMEunticked.
Next, openAndroid Studioand create a new project. Call your new applicationTestProject. ClickNextto continue.
Leave the next page as default?and clickNext.
On theAdd an activity to Mobilescreen selectBlank Activityand clickNext.
In the next screen, leave the default?activity name of MyActivity and click Finish.
Your new project will open in Android Studio. On the top menu, selectVCS>Import into Version Control>CreateGitRepository.
On the next screen, leave it all as default and clickOK.
Now use Internet Explorer and navigate to the root of your projects folder. Right click and selectGit Bash(If you do not see this option, then first installGit for Windows).
When the Git bash screen appears, type:
1
git remote add origin?https://github.com/[username]/[project_name].git
An example of a Git repository URL is:https://github.com/markwint/testproject.git
Then press enter. The GitHub remote will be added to your Git repository.
Next, jump back into Android Studio, right click your projects root directory and selectGit>Add. This will add all your project files to your Git repository.
It will seem like nothing has happened, but trust me, the project files are added.
Now right click the project name again and this time selectGit>Commit Directory.
In the next screen, type aCommit Messageand selectCommit.
If a Code Analysis warning appears, clickCommit. (Unless it’s a real project, in which case review and fix the issue before committing!)
Now, right click the project name, selectGit>Repository>Push.
Check the boxPush current branch to alternative branchand leave the branch name asmaster. Then selectpush.
Now enter your GitHubLogin(email address)?andPassword. Then clickOK.
If it’s all good, you will see this message.
Now your code is pushed to your GitHub repository. Don’t believe me? Logon and check for yourself.
上述轉(zhuǎn)自:http://blog.csdn.net/ganshuyu/article/details/41965853
還有篇不錯(cuò)的教程:http://blog.csdn.net/gao_chun/article/details/49817229/
注:
1友存、在? git remote add originhttps://github.com/[username]/xxx.git? 連接遠(yuǎn)程庫(kù)使可能會(huì)報(bào)錯(cuò)
fatal: remote origin already exists. 再悼,此時(shí)可以先
? ? ?(1)先刪除遠(yuǎn)程 Git 倉(cāng)庫(kù)
? ? ? ? ? ? ?$ git remote rm origin
? ? ? (2)再添加遠(yuǎn)程 Git 倉(cāng)庫(kù)
? ? ? ? ? ? ? $git remote add originhttps://github.com/[username]/xxx.git
2缎除、在push時(shí)可能報(bào)錯(cuò)Push rejected: Push to origin/master was rejected
? ? ? 出現(xiàn)錯(cuò)誤的主要原因是github中的README.md文件不在本地代碼目錄中
可以通過(guò)如下命令進(jìn)行代碼合并【注:pull=fetch+merge]
git pull --rebase origin master