Create a new Git repo

Last Update: 3/14/2017
Team Services | TFS 2015 & TFS 2017 | Visual Studio 2015 & 2017

Overview

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.

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.

Team Services | TFS 2015 & 2017 | Visual Studio 2015 (Update 2) and 2017

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 Visual Studio Team Services 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.

Open up a command prompt and navigate to the top-level folder containing your project's code, or a new folder if you are starting from scratch. Create the Git repository using the init command:

> git init .
Initialized empty Git repository in current directory

Work in branches to keep track of your work and create commits to snapshot your changes into Git.
Once you are ready to share your code, get the clone URL for the repository you want to connect to and then set up a remote relationship (in this case, origin) so your repo can push changes to a shared repo.

> git remote add origin https://fabrikam.visualstudio.com/Fabrikam/_git/FabrikamFiber

Push your changes to the origin repository to share with others:

> git push origin users/frank/feature

What's next

Save work with commits