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.
- If you plan to use TFS, create or get access to a team project.
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
|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.)
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.
- 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.
- Open and clone a repository in a Git team project
- Clone a remote Git repository from a third-party service
(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.
- 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 aslocally-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.
- 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.
- 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.