Share your code in Git

After you create your app, you can use a local Git repository to take snapshots of your code as  you work. When you want to share your code with your team, publish it to Visual Studio Online. Or, if your team already has code in a TFS-managed Git repository, clone it to your machine.

As you work, you can fetch code from the server to keep your codebase current. When your code is ready to share, push it to the team's repository.

Take snapshots of 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. If you haven't already, create an app.

  2. 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.

    When your changes are ready, select Commit  
  3. On the Changes page (Keyboard: Ctrl + 0, G), add a comment and then commit your changes.

    Add a comment and choose Commit 

    These changes are now committed.

    Your changes are now committed 

Publish your Git repository into your team project

  1. If you haven't already, connect to your team project.

  2. View your local Git repositories (Keyboard: Ctrl + 0, C).

    Go to the Connect page to see your local Git repositories 
  3. Publish your repository into your team project.

    Open the context menu for the Git repository and then choose Publish

    You've now shared your code with your team.

    Your repository has been published   

Clone your team's code

If you're joining a project that already has its code shared in a Git repository that's managed by Visual Studio Online, clone the repository to your machine.

  1. If you haven't already, connect to your team project.

  2. Clone the repository onto your dev machine.

    Choose Clone Repository 
  3. Store the repository locally.

    Choose Clone to store the repository locally
  4. Now that you've got your copy of the code, you can open the solution.

    Choose the solution name to open the solution in Visual Studio 
  5. Go to Solution Explorer (Keyboard: Ctrl + Alt + L).

    Open Solution Explorer 
    Now you're ready to add your code to your local Git repository!

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: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. Use Git from the command prompt.

Try this next