When you start using Visual Studio with Git, choose the way that works best for you and the kind of project you’re working on. For example, you can start an experimental solo effort in a new or an existing local repository and continue developing there as long as you want. Or you can join a collaborative effort in a remote Git repository, hosted either in Team Foundation Server (TFS) or on another service.
Before you start
If you don’t have Visual Studio, get it here.
What do you want to do?
Start from a local repository Start from your dev machine with a new solution or an existing solution, add an existing local repository, or create a new (init) empty repository
Start from a remote repository Start from a remote repository (hosted on either TFS or on another service) and then clone it to your dev machine
Customize Git settings on your dev machine Customize (config) how you identify yourself, specify the kinds of files you manage, and customize other settings
Get answers to common questions
You can create a local repository on your dev machine—whether or not you have a network connection—and start developing right away: coding, committing, branching, and merging code. When you’re ready to collaborate with your team, you can publish one or more branches from your local repository into a team project.
Create a new solution under local Git version control
Put an existing solution under local Git version control
Create or add a local repository
Publish your local repository into TFS
You've got an idea for a new app, so you want to experiment on your dev machine. In less than a minute you can use Visual Studio with Git to create a new code project under local version control. (And no Internet required!)
Create a new code project (Keyboard: Ctrl + Shift + N). We suggest that you put your new project in c:\Users\YourName\Source\Repos\.
You’ve already got an app in progress and you want to start working on it under local Git version control.
Before you add the solution to Git version control, we recommend you first move the solution to the TFS Git default location: c:\Users\YourName\Source\Repos\
If you have not already done so, open your solution, (Keyboard: Ctrl + Shift + O) and then open Solution Explorer (Keyboard: Ctrl + Alt + L).
Add your solution to source control.
On the Choose Source Control dialog box, choose Git.
Now that your repository is created, you are ready to commit your files. Go to the Changes page (Keyboard: Ctrl + 0, G) and commit.
(If you are prompted to configure your user name and email address, do that now. See Configure Git settings.)
You can create an empty local repository and add files later. It’s possible to track your changes to the files whether or not they are part of a solution. Or, if you already have a local repository, just start working with it in Visual Studio.
Open the Connect page (Keyboard: Press Ctrl + 0, C).
To create an empty local repository, choose New. To open a local repository that already exists on your dev machine, choose Add.
Specify the local path and then choose Create or Add.
When you are ready to share your code and collaborate with your teammates, publish your local repository into TFS.
Make sure you have committed all your changes in the local repository. See Manage and commit your changes.
If you haven’t already done so, create a new a new team project (choose Git version control) or create a new Git repository in an existing Git team project.
From the Connect page (Keyboard: Ctrl + 0, C), connect to the empty Git repository and publish the local repository to it.
Your friends have invited you to work with them on a new project. Or maybe you are setting up a new project or a new dev machine. You can use Visual Studio and Git to collaborate on TFS ( on-premises or in the cloud), on CodePlex, or on a third-party service such as GitHub or Bitbucket.
What do you want to do?
Open and clone a repository in a Git team project
Clone a remote Git repository from a third-party service
From Visual Studio: Go to the Team Explorer Connect page (Keyboard: Press Ctrl + 0, C) and then connect to the team project.
(If the team project you want to open is not listed, choose Select Team Projects and then connect to the team project.)
From the web: Open a team project from its home page in your web browser (Keyboard: Ctrl + 0, A).
After you connect to the Git team project, if you have not already done so, you must clone it to your dev machine before you can work in it.
Just specify the local path and choose Clone.
Does your team have some code in GitHub or another service such as CodePlex or Bitbucket? To start working in Visual Studio, clone the code to your dev machine.
To customize your Git settings, you must be connected to a local or remote Git repository. Open the Git Settings page.
Apply global settings Apply global Git settings to control aspects of how Git functions for the current user on the dev machine. For example, you can specify how you identify yourself on the changes you commit.
Apply repository settings Apply settings to control how Git functions in each individual local repository on your dev machine. For example, you can fine tune how the system blocks clutter from entering your user experience and repository.
Apply more settings Visual Studio respects all Git settings but provides you with control over only a few of them. Use the Git command prompt to customize all Git settings.
User Name and Email Address: Git associates each commit you create with your name and email address. When you start using Visual Studio with Git on your dev machine, if you connect to a Git team project first, then Visual Studio fills in your name and email address for you.
Default Repository Location: Specify the default root directory where you want to create or clone new local Git repositories.
Author images: Use images to more easily see the author of each commit.
An example of how author images enhance the collaborative experience:
If your repository does not have settings files, you should probably use Visual Studio to add some default files that apply the most typically useful settings. You’ll avoid distraction and potential clutter in your repository from non-source files such as locally-built binaries.
.gitignore file: See Use the Git ignore file to avoid file clutter in your work and in your repository.
.gitattributes file: To specify options such as how the system handles line-breaks, specify a .gitattributes file. See Customizing Git - Git Attributes
Commit your repository settings files: In most cases you should commit and push these files so that everyone else on your team uses the same repository settings on their dev machines.
You can specify three kinds of Git settings, listed in order of supersedence:
Repository settings apply to the work done in the local repository.
Global settings apply to the work done by the current user on the dev machine.
System settings apply to all work done on the client dev machine. (Visual Studio respects these settings, but does not expose them.)
If you need to modify system settings, or if you prefer the command prompt, then modify your Git settings from there. See Work from the Git command prompt, Customizing Git - Git Configuration, and git-config command.
A: Follow a step-by-step walkthrough to get started using Git to work locally on a new project and then to begin collaborating with a team on Visual Studio Online.
A: In most cases, it’s best to use a short, understandable folder path. For example: C:\Users\YourName\Source\Repos\FabrikamGit\SolutionName\.
Some tips on effective folder names:
Keep all folder, sub-folder, and file names short to simplify your work and avoid potential long-path issues that can occur with some types of code projects.
Avoid whitespace if you want make command-line operations a little easier to perform.
A: Yes, any contributor to your team project can claim any user name and any email address they want when authoring a commit. However, TFS does authenticate who pushes the commit. To see who pushed a commit, open your team project in your web browser (Keyboard: Ctrl + 0, A). Open the commit you want to examine from the Commits section, and then expand the commit details.