Getting to grips with Git, Visual Studio Online & Visual Studio


 

Lets start with some basics

1. Git is an open source version control system

2. GitHub is a Git repository hosting service

So what are some of the common terms you will encounter

Terms

Clone – creating a copy of the central repository with version control.

Once a repo has been cloned you can manage versions of the files that are located there and you can also select a specific version.

Add – Adding a file to a repo means that the file is now managed with version control.

New files need to be added before they can be shared with the repository. The Add operation is performed locally so will not impact the central repository until one of the following operations are performed.

Commit – Simply commits files, files need to be added before they can be committed. The commit operation is also carried out locally.

Push – With the push operation, the changes made locally are committed to the local index and will be replicated to the central repository So Push is a way to synchronize and share code updates.

Pull – When a Pull command is used it synchronizes the changes made between the central version and the local version. You should always use a pull command before you use a push command to ensure consistency of the central repository.

Pull Request – A pull request allows you to propose modifications to the code that exists in an existing repository. The proposed changes will then be discussed by the owner of the code and potentially pulled into the central repository.

Setting up your Workstation 

Visual Studio 2015 add/remove features simply select Git features

clip_image001

If your using a Mac or windows you can download Git from http://git-scm.com/downloads

You can also install GUI based Git at the following location http://git-scm.com/downloads/guis

image

Configure Git

from Git Bash use the following commands

   1: $ git config --global user.name "Your Name"
   2: $ git config --global user.email "Your Email Address"

1. Create a folder

This can be done with Git Gui

image

You can now open the selected repository open with Git Bash

Cloning an existing repository

For this we will clone the Azure Quick Start Templates

Simply type

image

Uploading content to Visual Studio Online Account

Students can setup a FREE Visual Studio Online via DreamSpark https://www.dreamspark.com/Product/Product.aspx?productid=99

Configure your account in Visual Studio Online for secondary user

1. Login to Visual Studio online

2. Select your user account and then my profile

3. Select the security tab

4. Select Enable Alternate authentication credentials and create a new account.

image[42]

Clone your Visual Studio Respoistry with Git

1. Create a directory that you want to use then go to that within Git Bash

2. Locate in your visual studio online url that you want to use to clone this repository

image

3. Simply select the clone button to show you the url

4. From a Git Bash prompt type the following command (replace the url with your url)

Now you can modify the files from the copy

To Push the content to Visual Studio Online

To add and upload modified files to the Visual Studio Online repository

Create a new folder

   1: $ git add.

Then commit the changes

   1: $ git commit -m "my first commit, always document commits why" 

Then upload the content to Visual Studio Online

   1: $ git push

You can now verify the content has been uploaded to Visual Studio Online

You can alternatively do the code changes add, commit and pushes from directly within Visual Studio 2013 or 2015 see the following instructions

Clone your repository from Visual Studio

  1. Clone the repository onto your dev machine with Visual Studio.

  2. Choose Clone Repository

     

     

  3. Store the repository locally.

    Choose Clone to store the repository locally

Create a new app

If you don’t already have an app in the repo, create one.

  1. Create a new project.

    New solution from team explorer

  2. Choose a template and add the new code project to version control.

    Choose a template

Confirm your settings and add the app

  1. On the changes page (Keyboard: Ctrl + 0, G), if you haven’t already done it, confirm your user name and email address.

    Configure settings from the changes page

    Confirm the default settings

  2. Add a comment and commit your app to version control.

    Add app to version control on Changes page

Snapshot (commit) your code

With your code project stored in a local Git repository on your dev machine, you can commit as early and as often as you like.

 

  1. As you write your code, your changes are automatically tracked by Visual Studio. You can commit one or more specific changes to your local repository from Solution Explorer (Keyboard: Ctrl + Alt + L).

    When your changes are ready, select Commit

  2. On the Changes page, add a comment and then commit your changes.

    Add a comment and choose Commit

    These changes are now committed.

    Your changes are now committed

Pull changes from your team

Pull changes on a regular basis to ensure your code integrates well with the latest code from the team.

  1. From the commits page (Keyboard: Ctrl + 0, O), fetch the commits to see any changes that your team has made.

    Choose Fetch to see any changes that your team has made

  2. When you’re ready, pull these commits into your local repository.

    Choose Pull to get these commits locally

  3. The changes from your team are now integrated in your local repository.

    The changes are now integrated

Push your local commits to the server

When the code you’ve written on your dev machine is ready, you can push your changes from your local Git repository to the team project.

  1. From the changes page (Keyboard: Ctrl + 0, G), make sure you’ve committed your changes.

    Commiting from the Changes page

  2. Go to the commits page (Keyboard: Ctrl + 0, C).

    Push changes

  3. Push your changes.

    Push changes

Q&A

Q: Why is my sign-in page different than when I sign in to Visual Studio?

A: Your sign-in page depends on whether you used a Microsoft account or work account with Visual Studio Online. So, sign in with the username and password that you used with Visual Studio Online.

Q: Why doesn’t Visual Studio launch when I click "Open in Visual Studio" on my team project page?

A: This link requires Visual Studio 2013 or later. It doesn’t launch earlier versions of Visual Studio.

Q: Can I use earlier versions of Visual Studio to connect to Visual Studio Online?

A: Yes, you can use Visual Studio 2013 or 2012. You can also use Visual Studio 2010, but you’ll need to install Service Pack 1 and KB2662296 first. Or, you can use Visual Studio 2008 SP1, with this GDR update. Launch Visual Studio, then connect to Visual Studio Online using your account URL, and select your team project.

Q: How can I see what I’ve changed?

A: To see what you’ve changed, compare your changes with the last commit.

Choose Compare with Unmodified from the context menu

Q: How can I get more information about the commits from my team before I pull them?

A: Sometimes you need to see the details about incoming commits from your team. That way you can understand how a change will integrate with your work.

Choose View Commit Details

You can get details on the changes to each file.

Choose Compare with Previous from the context menu

Q: How do I associate my changes with related work items?

A: From the changes page you can run a query, and then drag a work item into the list of related work items.

Associating a work item on the Changes page

Q: Can I use Git command-prompt tools?

A: Yes. See Use Git from the command prompt.

Q: Where can I learn more?

A: Use Visual Studio and Team Foundation Server with Git

Comments (0)

Skip to main content