Create a new Git repo

VSTS | TFS 2018 | TFS 2017 | TFS 2015 | VS 2017 | VS 2015 Update 2

A Git repository, or repo, is a folder that you’ve told Git to help you track file changes in. You can have any number of repos on your computer, each stored in their own folder. Each Git repo on your system is independent, so changes saved in one Git repo don’t affect the contents of another.

A Git repo contains every version of every file saved in the repo. Git saves these files very efficiently, so having a large number of versions doesn’t mean that it uses a lot of disk space. Storing each version of your files helps Git merge code better and makes working with multiple versions of your code quick and easy.

In this tutorial you learn how to:

  • Create a new Git repo

Video tutorial

The following video explains what Git repos are, and shows you how to create them on your computer using Visual Studio 2015 Update 2.

Tip

Working from the command line? You can view our video overview using command line steps on Channel9.

Create a new repo

Manage any folder with source code or Visual Studio solution in Git by creating a repo for them. Later you can connect this Git repo to a remote Git repo to share your work with others.

Create a repo

From a new solution

Create a new Git repo for your new Visual Studio solution by selecting Create new Git repository when creating the solution:

Select Create new Git reposistory when creating a new solution

From an existing solution

To create a repo from an existing solution not in version control, select the Publish button in the bottom-right of the lower status bar Visual Studio publish button. This creates a new Git repo in the same directory as your solution and opens up the Publish view in Team Explorer so you can push your code to VSTS or another remote Git repository.

Publishing a solution to a new remote Git repository in Visual Studio Team Explorer

In an empty folder

  1. Open the Connect view in Team Explorer by choosing Projects then Manage Connections from the context menu.
  2. Under Local Git Repositories, select New and enter a folder where the repo will be created. This directory must be empty.
  3. Select Create to create the repo.

    Creating a new local Git repository in Visual Studio Team Explorer

Connect a local repo to a remote

To connect a local repository to a hosted remote Git repository to share your work, go the Settings page in Team Explorer. Select Repository Settings. Under Remotes, select Add.

Add a remote for a repo in Visual Studio Team Explorer

Enter origin in the Name field and enter the clone URL for your repo in the Fetch field. Make sure that Push matches fetch is checked and select Save.

Next steps