Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change git branch in Android Studio

I have 2 branches in my gitlab project. Now I'm on the master (default) branch. I want to change it to another base, this is what I tried:

When I go to VCS -> Git -> Branches, and click Checkout tag or revision I always get an error :

pathspec 'my branch' did not match any files known to git

What should I do? All I want to do is to change the branch and do a pull request.

like image 239
Blaze Tama Avatar asked Sep 21 '15 12:09

Blaze Tama


People also ask

How can I see my git branch in Android Studio?

Go to VCS > Git > Branches. “Git Branches” appears. It shows all the local branches and remote branches as well as the “New branch” option. Tip: If you look at the right corner of Android Studio, you also see your current branch — clicking it will also opens the “Git Branches” popup.

How do I change a remote branch?

In order to fetch these changes from your remote, or in other words, download the changes to your local branch, you will perform a Git pull. Under the covers, a Git pull is actually a Git fetch followed by a Git merge. Git pull is just a shortcut to perform both of these actions in one step.


2 Answers

To checkout a different branch from within Android Studio:

Under VCS -> Git -> Branches you will see this screen

enter image description here

under Local branches you will see the local branches you can checkout. At the very bottom you see the currently checked out branch (in my case master). To checkout a different branch, select it and click Checkout.

enter image description here

In my example I only have one other local branch, named test. That is why it only shows that one.

After checking out a different branch, this window will pop up in the bottom of the screen

enter image description here


In order to get your remote branches to show up in Android Studio, you first need to fetch them:

VCS -> Git -> Fetch. After that, it will show up

enter image description here

like image 80
Tim Avatar answered Sep 20 '22 14:09

Tim


I've noticed that when I try this flow, and then paste the branch name in, I get:

Couldn't checkout foo: fatal: 'foo^0' is not a valid branch name. I don't what is inserting the ^0 a the end,

So I instead just call git checkout (paste branch name) from the command line, which works.

like image 39
MK. Avatar answered Sep 20 '22 14:09

MK.