Get a Specific Branch Of GitHub Repo Using Xamarin Studio

A few months back, Miguel de Icaza tweeted that they are working on a Xamarin.Forms version of Mac and I got excited, as I always wanted to develop apps for Mac but didn’t want to invest my time in learning the working of Xamarin.Mac. Also, I am more comfortable and good (that’s what I think ) in Xamarin.Forms.

The Tweet that got me excited

From Twitter itself, I came to know that there is a separate branch for macOS in Xamarin.Forms Github Repository (Branch Link). I wanted to contribute to this library so I forked it (for those who are new to GitHub, the term forking means copying a Github repository from someone else's public repository to your GitHub account. This way the actual user will work on his copy and you will work on your own), but to my dismay, the copy which was created for my user was of a master branch of the Xamarin.Forms repository, not the macOS one. Later, I learned that forking creates a complete copy of the repository you forked in your account along with the all its branches. Now, the question arises, how will you work on the branch you want to work on, in my case the MacOS branch?

I searched for the solution all over the internet and finally was able to clone the MacOS branch on my local. This blog is a step by step guide on how to clone a particular branch of any repository using Xamarin Studio. In this article, I will be cloning the macOS branch of Xamarin.Forms repository.

Step 1

Open the repository you want to fork in Github and click on ‘Fork’ button, as shown in following image.

Step 2

Once the forking is complete, you will be redirected to your repository’s page with master branch selected.

Step 3

Click on "Clone or Download" button and copy the path mentioned in the text box, as shown in the below image.

Step 4

Open Xamarin Studio (to clone the repository on your Mac) and click on Version Control–> Checkout... option.

Step 5

The previous step will open the following window.

Step 6

Paste the path you copied from the web, in the URL text box and it will automatically fill in the rest of the fields.

Step 7

If you want to change the location where you store the code locally, you can do so by changing the ‘Target Path‘ and then, click on checkout to clone the repository locally.

Step 8

Xamarin Studio will download the master branch of the code and open the solution in Xamarin Studio.

Step 9

In order to get a particular branch of the code and work with it, we need to set that branch as a remote source and create a copy of the same. To do so, click on the option Version Control –> Manage Branches and Remotes, like below.

Step 10

The previous step will open the following window. You can see that by default, the "Branches" tab is selected, which shows all the branches cloned locally and it will be master, by default. Click on ‘Remote Sources’ tab as highlighted.

Step 11

‘Remote Sources’ tab will show the origin collapsed in Remote Source / Branch with URL, as below.

Step 12

Click on the arrow adjacent to origin (as highlighted below), which will list down all the branches of the repository (like next Image).

Step 13

Scroll through the list and select the desired branch (macOS in our case), as shown below.

Step 14

If you notice the images of Step 11 and 12, you will notice that there is a button titled ‘Track in local Branch’ which was disabled in step 11 and got enabled in step 12 when we selected our desired branch --  click on button to clone the branch locally.

Step 15

You will get following window to set branch properties in order to set local name etc. Click on Ok button (Don’t change the name as it will help to relate with the online branch) and the window will go away, now if you click on Branches tab you will see that it will show another branch in the list as shown in the next image; close the window by clicking in the close button.

Step 16

Click on Version Control menu and you will see that now there is a new option ‘Switch to Branch’ giving an option to change the branch as the below Image. It will still be showing the master branch as checked, click on macOS branch to clone and open.

Step 17

The following window will appear once you click on macOS branch in Switch to Branch option. Enter your details (your GitHub username and email) and click OK button.

Step 18

Xamarin Studio will download the code of the branch and open the solution like below. Also, you can see the branch name in brackets (as highlighted).

Now, you also can download any particular branch of any public code repository from Github and work on the same. Let me know if I have missed anything, or if you have suggestions or if there is any particular topic in Xamarin you want to know about.

Up Next
    Ebook Download
    View all
    View all