Home and Learn: Intermediate Programming


Git Version Control, Branches

Stick Figure App - Version Control

 

A Branch, sometimes called a Fork, is the equivalent of copying and pasting your entire project. You'll then have two versions you can work on, an original version, called the master, and a copy. You can create as many branches as you want. If you had your project stored in a repository (a repo) other people could download a copy of it. They would then be working on their own branch.

Because you've just spent a lot of time designing your form in the previous lessons, it would be a good idea to create a branch from it. If anything goes wrong, you can always call up the original version (the master) and create another branch from it. Or you might just want to go in a different direction with the completed form, by adding new features, for example.

Click on the Branches item in the Team Explorer. You'll see this:

The Branches tab on the Visual Studio Team Explorer panel

Click on New Branch:

The New Branch item highlighted on the Visual Studio Team Explorer panel

When you click on New Branch, you'll be prompted to enter a name for it:

The prompt to enter a new name for your branch

Click inside the yellow text box and enter a name. Call it DrawingProgramBranchOne:

A Branch with a new name

When you've entered the name, make sure there is a tick in the Checkout branch box. (Checking out means you're now working on this branch.) Then click the Create Branch button in the bottom left of the Team Explorer. The tab will then change to this:

A New Branch created and checked out in Git

The highlighted branch is the one you're working on.

Now have a look at the bottom of Visual Studio again. In the bottom right, on the blue bar, you'll see the name of the branch you currently have checked out:

Version Control menu in Visual Studio

The two arrows going left and right indicate a branch. DrawingProgramBranchOne is the branch we have checked out. The single arrow on the far left pointing up is where you can upload (push) your changes to an online repo. We haven't got an online repo, so we'll leave pushing alone. The 0 to the right of the little pencil indicates the changes you have made to this branch. We haven't made any changes yet, which is why it's a zero.

But click on DrawingProgramBranchOne and you'll see a menu appear. This one:

The Branch menu in Visual Studio

Rather confusingly, the highlighted item is not the branch you're working on. The branch you're working on is the one at the top. It's greyed out and has a check mark to the left of it. If you wanted to switch back to the original version of your program, you'd click on master. If you quickly want to switch between branches, this is the place to do it.

OK, let's make some changes to our program and see what happens. We'll do that in the next lesson when you'll learn about committing changes.

Commit Changes in Git >>

<< Back to the Intermediate Contents Page


Email us: enquiry at homeandlearn.co.uk