How to use git branch with Android Studio

六月ゝ 毕业季﹏ 提交于 2019-11-28 15:46:47

问题


I am new to git. I have a very simple scenario for using git. I had my first release written with Android Studio. Now I want to work with some new features. What I did so far:

  1. enabled the VCS in my Android Studio
  2. created a local repository for my project from Android Studio
  3. pushed my local repository to my Bitbucket remote repository ($git push -u origin master)

Now I am confused for the next step: create a feature branch. Should I create a branch in the local repository:

$ git branch --track feature1 origin/master 

or should I create a new branch from the Bitbucket web portal, and clone the new branch?

I also want to know how I can switch branches with Android Studio? For example, switch from feature branch to master branch to work on some hotfix. Do I need to use the Bitbucket plugin to checkout the project very time from the remote repository every time I switch branches or I can hot switch it inside Android Studio?

Thanks!


回答1:


You should be able to do this directly from Android studio.

The easiest way is going to the bottom right corner of the Android Studio window where you should see the text "Git: branch name", in your case it should say "Git: master". Click on it and it will show a small menu consisting of the different branches available both locally and remotely, also there should be an option "+ New Branch" which will create a new branch for you and switch you to it.

You should then be able to change some code, commit it and push it to remote. Merging and checking out branches can also be done from that same menu. The same thing can also be done from the menubar option "VCS"




回答2:


Here's the best way I know to update the remote branches in Android Studio 1.5

1) Go to VCS > Git > Pull (make sure you've pulled your latest changes from master first)

2) Click the blue refresh button on this screen

3) notice all your new branches show up, click on the checkbox of the one you want to switch to and click "Pull" button

4) go back to the "Git:master" menu in the bottom right of Android Studio, and you'll notice your new branch showed up in the remote section

5) click on the branch you want to checkout and select "Check out as new local branch"




回答3:


you can do it easily by the shell (Git Bash is recommended) and trying the following for the first time:

 git pull [remote] [branch]

for example:

git pull origin master

after this, you can always do the matter without any trouble like that.



来源:https://stackoverflow.com/questions/24657326/how-to-use-git-branch-with-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!